A data frame I created from a csv I imported cannot be seen in ggplot2. I inspected the frame and I am pretty sure it's there but I am new to R. This is a frame that appeared to work with every function but when it came to this one it stopped working. This is my code:
visualize(height_diff_under_null) +
shade_p_value(obs_stat = obs_diff_position_height, direction = "both") +
labs(x = "Difference in mean height for forwards and centers", y = "Count",
title = "Null distribution of differences in forward and center height",
subtitle = "Actual difference observed in the data is marked in red"
)
Environment showing csv and the data frame:
After adding the code:
dput(head(height_diff_under_null, 20))
result:
structure(list(replicate = 1:20, stat = c(0.254006410256409,
-0.362847222222229, -0.104166666666671, -0.0643696581196593,
0.0152243589743648, 0.0550213675213627, -0.323050213675216, 0.114716880341874,
0.0351228632478637, 0.174412393162399, 0.612179487179489, 0.174412393162399,
-0.0444711538461604, -0.502136752136749, -0.00467414529914834,
0.134615384615387, 0.0351228632478637, 0.492788461538467, -0.0842681623931583,
-0.402644230769226)), row.names = c(NA, -20L), class = c("infer",
"tbl_df", "tbl", "data.frame"), response = height, explanatory = position, response_type = "numeric", explanatory_type = c(`explanatory_variable(x)` = "factor"), distr_param = c(df = 151.819892587405), null = "independence", theory_type = "Two sample t", generated = TRUE, type = "permute", hypothesized = TRUE, formula = height ~
position, fitted = FALSE, stat = "diff in means")
So I tried to use that code and I'm not sure if I used it right
library(tidyverse)
height_diff_under_null %>%
ggplot(aes(x = stat)) +
geom_histogram(bins = 10) +
visualize(height_diff_under_null) +
shade_p_value(obs_stat = obs_diff_position_height, direction = "both") +
labs(x = "Difference in mean height for forwards and centers", y = "Count",
title = "Null distribution of differences in forward and center height",
subtitle = "Actual difference observed in the data is marked in red"
)
The result:
Error in `ggplot_add()`:
! Can't add `visualize(height_diff_under_null)` to a ggplot object.
Backtrace:
1. ggplot2:::`+.gg`(...)
2. ggplot2:::add_ggplot(e1, e2, e2name)
4. ggplot2:::ggplot_add.default(object, p, objectname)
Error in ggplot_add(object, p, objectname) :
The error I received after adding to the top:
height_diff_under_null %>%
ggplot(aes(x = stat)) +
geom_histogram(bins = 10) +
visualize(height_diff_under_null) +
shade_p_value(obs_stat = obs_diff_position_height, direction = "both") +
labs(x = "Difference in mean height for forwards and centers", y = "Count",
title = "Null distribution of differences in forward and center height",
subtitle = "Actual difference observed in the data is marked in red"
)
The error:
Error in `ggplot_add()`:
! Can't add `visualize(height_diff_under_null)` to a ggplot object.
Backtrace:
1. ggplot2:::`+.gg`(...)
2. ggplot2:::add_ggplot(e1, e2, e2name)
4. ggplot2:::ggplot_add.default(object, p, objectname)
Error in ggplot_add(object, p, objectname) :
Pic of error:
After testing Mark's code: Mark's code in new file
Photos for Phil libraries Environment