我在R中绘制了ggplot条形图。我想根据这里的情节缩放Y轴....
我的值范围为0-26000。我想用比例0,30,26000绘制条形图。我尝试过使用breaks = c(0,30,2600),但是它会打破休息时间。
这是带有缩放轴的图。
http://wego.genomics.org.cn/cgi-bin/wego/index.pl
如何在R?
中实现这一目标任何想法。?
答案 0 :(得分:0)
这样的东西?
library(ggplot2)
# generate sample data...
set.seed(1)
df <- data.frame(x=LETTERS[1:10],y=sample(1:10,10)^sample(1:5,10,replace=T))
# plot the data...
ggplot(df,aes(x,y))+
geom_bar(stat="bin",fill="lightgreen",color="grey50")+
scale_y_continuous(trans="log1p", breaks=c(0,30,2600))
这样做的唯一方法是使用y轴的某种数学变换;否则,图表毫无意义。由于您的数据涵盖&gt; 4个数量级,日志转换是一个很好的候选者,除了你想要0
作为下限。所以我使用了“log1p”变换,它可以缩放为log(y + 1)。
如果您加载scales
包(library(scales)
)并输入?trans
,您会看到很长的可用比例转换列表。奇怪的是,要像我上面那样在ggplot
中实际使用这些,您不必加载scales
包。