我有数据可以看到两种不同物种的单一栽培和混合栽培之间的生长差异.此外,我制作了一个图表,以使我的数据清晰.
我想要一个带有误差条的条形图,整个数据集当然更大,但是对于这个图,这是data.frame带有条形图的方法.
plant species means
Mixed culture Elytrigia 0.886625
Monoculture Elytrigia 1.022667
Monoculture Festuca 0.314375
Mixed culture Festuca 0.078125
Run Code Online (Sandbox Code Playgroud)
有了这个数据I作出的曲线图ggplot2,其中plant是在x轴和means所述y轴和I中使用的小面来划分种类.
这是我的代码:
limits <- aes(ymax = meansS$means + eS$se, ymin=meansS$means - eS$se)
dodge <- position_dodge(width=0.9)
myplot <- ggplot(data=meansS, aes(x=plant, y=means, fill=plant)) + facet_grid(. ~ species)
myplot <- myplot + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25)
myplot <- myplot + scale_fill_manual(values=c("#6495ED","#FF7F50"))
myplot <- myplot + labs(x = "Plant treatment", y = "Shoot biomass (gr)")
myplot …Run Code Online (Sandbox Code Playgroud) library(tidyverse)
ggplot(mpg, aes(cty, hwy)) +
geom_point() +
facet_grid(year ~ fl) +
geom_hline(yintercept = mean(mpg$hwy))
Run Code Online (Sandbox Code Playgroud)
我希望geom_hline()上面显示的方面中的每个都是仅包含在该方面中的点的平均值。我认为我可以用(如下)之类的东西来做到这一点。但这不起作用。我很接近,对吧?
library(tidyverse)
ggplot(mpg, aes(cty, hwy)) +
geom_point() +
facet_grid(year ~ fl) +
geom_hline(yintercept = mean(mpg %>% group_by(year, fl)$hwy))
Run Code Online (Sandbox Code Playgroud)