我试图按照这篇文章https://www.datanovia.com/en/lessons/ggplot-error-bars/做一个带有误差线的图。但是总结不太起作用。为什么?
> df$dose <- as.factor(df$dose)
> head(df, 3)
len supp dose
1 4.2 VC 0.5
2 11.5 VC 0.5
3 7.3 VC 0.5
> df.summary <- df %>%
+ group_by(dose) %>%
+ summarise(
+ sd = sd(len, na.rm = TRUE),
+ len = mean(len)
+ )
> df.summary
sd len
1 7.649315 18.81333
字符串
但看起来你应该得到这样的东西:
## # A tibble: 3 x 3
## dose sd len
## <fct> <dbl> <dbl>
## 1 0.5 4.50 10.6
## 2 1 4.42 19.7
## 3 2 3.77 26.1
型
尝试了第一个答案,但仍然不起作用
> df <- data.frame(len = runif(30, 4.2, 11.5), supp = "VC", dose = sample(c(.5, 1, 2), 30, replace = TRUE))
> df.summary <- df %>%
+ group_by(dose) %>%
+ summarise(
+ sd = sd(len, na.rm = TRUE),
+ len = mean(len)
+ )
> df.summary
sd len
1 2.385391 8.057899
> dput(df[1:10,])
structure(list(len = c(6.38568101720884, 9.66049139532261, 6.71973214379977,
9.11211366723292, 10.07433216176, 8.6760600333102, 5.71324644873384,
4.77394210803322, 10.921557949041, 4.29420428201556), supp = c("VC",
"VC", "VC", "VC", "VC", "VC", "VC", "VC", "VC", "VC"), dose = c(2,
1, 2, 0.5, 1, 2, 0.5, 1, 1, 1)), row.names = c(NA, 10L), class = "data.frame")
型
1条答案
按热度按时间z8dt9xmd1#
我建议你使用
tidyverse
加载必要的库,不要使用被取代的plyr
。像这样:字符串