我正在开发一个相当简单的图形项目,并且无法使position_dodge
代码适用于ggplot2中的三重组条形图。
我的小融化数据框在这里:
structure(list(month = c(6, 7, 8, 6, 7, 8, 6, 7, 8), variable = structure(c(1L,
1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L), .Label = c("Min", "Max", "Avg"
), class = "factor"), value = c(1.3, 2.52258064516129, 4.28709677419355,
1.85666666666667, 2.13870967741935, 4.06129032258064, 1.56666666666667,
2.32903225806452, 4.16129032258065)), row.names = c(NA, -9L), .Names = c("month",
"variable", "value"), class = "data.frame")
有效的绘图代码不包含position_dodge
,其中包含:
ggplot(PJM.data, aes(x= factor(month), y= value, fill = variable)) +
geom_bar(stat="identity", position = "dodge") +
geom_text(aes(label= paste(round(value, digits = 1), "°F", sep = ""), vjust= -0.25))+
scale_fill_manual("Temperature Mean", values= c("steelblue","firebrick1","gold2"))+ ggtitle("Summer 2016 PJM Temperatures") +
labs(y= "Temperature Anomaly°F")
它产生这个图像:
每当我尝试将position_dodge
添加到我的代码的geom_text
部分时,情节会跳起来并给我这个错误:
Don't know how to automatically pick scale for object of type PositionDodge/Position/ggproto. Defaulting to continuous.
Error: Aesthetics must be either length 1 or the same as the data (9): label, vjust, position, x, y, fill
我试图将position_dodge的宽度值更改为许多不同的值,甚至将相同的参数包含在geom_bar部分中。我已经查阅了两个类似的帖子(Position geom_text on dodged barplot和Position geom_text on dodged barplot),但我无法弄清楚为什么这些简单的解决方案对我的数据不起作用。
有什么建议吗?
感谢。