我正在使用R和ggplot来绘制一些数据的散点图,除了y轴上的数字是以计算机样式的指数格式输出的,即4e+05,5e+05等。这对我来说是不可接受的,所以我想让它显示它们为500,000,400,000,等等。获得适当的指数表示法也是可以接受的。
该图的代码如下:
p <- ggplot(valids, aes(x=Test, y=Values)) +
geom_point(position="jitter") +
facet_grid(. ~ Facet) +
scale_y_continuous(name="Fluorescent intensity/arbitrary units") +
scale_x_discrete(name="Test repeat") +
stat_summary(fun.ymin=median, fun.ymax=median, fun.y=median, geom="crossbar")
任何帮助都非常感谢。
发布于 2014-06-16 18:48:28
我还发现了另一种方法,在轴上给出适当的‘x10(上标)5’符号。我把它贴在这里,希望它能对一些人有用。我的代码是从here得到的,所以我没有声称这是功劳,这理所当然地属于Brian Diggs。
fancy_scientific <- function(l) {
# turn in to character string in scientific notation
l <- format(l, scientific = TRUE)
# quote the part before the exponent to keep all the digits
l <- gsub("^(.*)e", "'\\1'e", l)
# turn the 'e+' into plotmath format
l <- gsub("e", "%*%10^", l)
# return this as an expression
parse(text=l)
}
然后,您可以将其用作
ggplot(data=df, aes(x=x, y=y)) +
geom_point() +
scale_y_continuous(labels=fancy_scientific)
发布于 2012-07-23 19:41:26
另一种方法是使用package scales
将轴记号标签格式化为逗号,然后添加
scale_y_continuous(name="Fluorescent intensity/arbitrary units", labels = comma)
添加到您的ggplot语句。
如果您不想加载包,请使用:
scale_y_continuous(name="Fluorescent intensity/arbitrary units", labels = scales::comma)
发布于 2012-07-23 18:26:27
x <- rnorm(10) * 100000
y <- seq(0, 1, length = 10)
p <- qplot(x, y)
library(scales)
p + scale_x_continuous(labels = comma)
https://stackoverflow.com/questions/11610377
复制相似问题