【发布时间】:2018-10-05 03:15:13
【问题描述】:
我在 R 中有一个这样的代码段,用于绘图:
plot_bar <- function(x, y, min, max, color = plot_colors[2]) {
p <- ggplot(data.frame(as.integer(x), y)) +
geom_bar(aes(x, y), stat = "identity", position = "dodge", fill = color) + ylim(min, max) +
theme_light() + theme(text = element_text(size = 25), axis.title.x = element_blank(), axis.title.y = element_blank())
return(p)
}
这对我有用,并产生如下内容:
基本上,(-2,+2) 从函数中的 min 和 max 参数的值传递到我的绘图。但问题是,我想要(-0.1%,+0.1%) 而不是 y 轴的 (-2.+2)。是否可以改变y轴的文字?
【问题讨论】:
-
this 是具有相关回复的类似帖子。
-
见
?scale_y_continuous。要格式化为百分比,请传递labels = scales::percent。不过,您似乎还想要一个转换,您需要为此显示一些数据。