這已被問及其他帖子,但我還沒有想出如何正確使用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
對不起。修正了它 –