我在使用带有log10比例的坐标转换时遇到ggplot问题。我希望在log10轴上绘制数据,但不缩放数据本身。这与sqrt一起使用,但是当使用日志轴坐标时,不会出现任何条形。请你告诉我我错过了什么?
d <- data.frame(x=factor(c(1,1,2,2)), y=c(1,2,3,4), fill=factor(c(1,2,3,4)))
#sqrt axis tranformaion works
ggplot(d, aes(x = x, fill = fill)) +
geom_bar(aes(y = y), stat = "identity", position = "dodge") +
coord_trans(y = "sqrt")
#log10 axis tranformaion doesn't work
ggplot(d, aes(x = x, fill = fill)) +
geom_bar(aes(y = y), stat = "identity", position = "dodge") +
coord_trans(y = "log10")
#log10 axis tranformaion works with points rather than bars
ggplot(d, aes(x = x, fill = fill)) +
geom_point(aes(y = y), stat = "identity") +
coord_trans(y = "log10")
答案 0 :(得分:0)
尝试使用scale_y_log10
功能:
ggplot(d, aes(x = x, fill = fill)) +
geom_bar(aes(y = y), stat = "identity", position = "dodge") +
scale_y_log10()