这已被问及其他帖子,但我还没有想出如何正确使用position_dodge
。ggplot2 - 如何在条形图上居中放置置信区间吧
如何将图形中每个栏中的每个CI栏居中?
df <- structure(list(Ano = c(2012, 2012, 2012, 2016, 2016, 2016),
Grupo = c("Controle", "Tratado", "Total",
"Controle", "Tratado", "Total"),
Margem_Mediana = c(4.4,3.1, 4.2, 3.8, 2.5, 3.6),
Erro_Padrao = c(0.0236, 0.0460, 0.0214, 0.0257, 0.0478, 0.0231)),
class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA, -6L), .Names = c("Ano", "Grupo", "Margem_Mediana", "CI"))
ggplot(df, aes(x = Ano, y = Margem_Mediana, fill = Grupo)) +
geom_bar(data = subset(df, Grupo != 'Total'),
position = position_dodge(), stat = 'identity') +
geom_errorbar(data = subset(df, Grupo != 'Total'),
aes(ymin = Margem_Mediana - CI,
ymax = Margem_Mediana + CI),
width = 1.5,
size = 0.5)
请修改您的代码,将'df < - '改为'graf_votos <-'和'.Names = c(“Ano”,“Grupo”,“Margem_Mediana”,“CI”)'改为'.Names = c (“Ano”,“Grupo”,“Margem_Mediana”,“Erro_Padrao”) – kitman0804
对不起。修正了它 –