ggplot2 barplot处理1个异常值,将轴向上推 [英] ggplot2 barplot dealing with 1 outlier pushing the axis up
问题描述
可能存在重复:
使用ggplot2,我可以在轴上插入一个中断吗?
我使用下面的ggplot2代码生成faces_grid barlot:
ggplot(plotobj,aes(as.factor(gm),peaks,fill = rvalue))+
geom_bar(stat =identity)+
facet_grid(rvalue〜。,scales =free) +
opts(legend.position =none)
第一个方面的截图):
正如您所看到的,由于1个异常值,y轴伸展到相当高的值。我想要做的是创造一个更明智的缩放比例,让更多的蜱直到2e + 05,然后只有1个蜱直接朝向5e + 05。通过这种方式,缩放比例不再是线性的,但它可以表明对于其中一个类别存在大量高峰。
反正用ggplot2做这个简单吗?有这样的R技巧吗?如果可能的话,我不想使用ylim之类的东西,只是不再显示顶部。
您可以在y轴上使用转换。
ggplot(plotobj,aes(as.factor(gm),peaks,fill = rvalue))+
geom_bar(stat =identity)+ facet_grid(rvalue〜。,scales =free)+
opts(legend.position =none)+ scale_y_log10()
ggplot(plotobj,aes(as.factor(gm),peaks,fill = rvalue))+
geom_bar(stat =identity)+ facet_grid(rvalue〜。,scales =free)+
opts(legend.position =none)+ scale_y_sqrt()
ggplot(plotobj,aes(as.factor(gm),peaks,fill = rvalue))+
geom_bar(stat =identity)+ facet_grid(rvalue〜。,scales =free)+
opts(legend.position =none)+ coord_trans(y =log10)
ggplot(plotobj, aes(as.factor(gm),peaks,fill = rvalue))+
geom_bar(stat =identity)+ facet_grid(rvalue〜。,scales =free)+
opts .position =none)+ coord_trans(y =sqrt)
Possible Duplicate:
Using ggplot2, can I insert a break in the axis?
I'm using the following ggplot2 code to generate a faced_grid barplots:
ggplot(plotobj, aes(as.factor(gm) , peaks, fill=rvalue)) +
geom_bar(stat="identity") +
facet_grid(rvalue ~ .,scales="free") +
opts(legend.position = "none")
Which gives the following plot (screenshot of the first facet):
As you can see the y-axis get stretched to quite a high value because of 1 outlier. What I'd like to do is create a more sensible scaling by having more ticks until 2e+05 and then just have 1 tick that goes directly towards 5e+05. This way the scaling would not be linear anymore but it would allow to show that there is a massive peak for 1 of the categories.
Is there anyway of doing this simple with ggplot2? Is there a R trick for doing this? If possible I'd not like to use things like ylim to just not show the top anymore.
You could use a transformation on the y-axis. Untested since you did not provide a reproducible example.
ggplot(plotobj, aes(as.factor(gm) , peaks, fill=rvalue)) +
geom_bar(stat="identity") + facet_grid(rvalue ~ .,scales="free") +
opts(legend.position = "none") + scale_y_log10()
ggplot(plotobj, aes(as.factor(gm) , peaks, fill=rvalue)) +
geom_bar(stat="identity") + facet_grid(rvalue ~ .,scales="free") +
opts(legend.position = "none") + scale_y_sqrt()
ggplot(plotobj, aes(as.factor(gm) , peaks, fill=rvalue)) +
geom_bar(stat="identity") + facet_grid(rvalue ~ .,scales="free") +
opts(legend.position = "none") + coord_trans(y = "log10")
ggplot(plotobj, aes(as.factor(gm) , peaks, fill=rvalue)) +
geom_bar(stat="identity") + facet_grid(rvalue ~ .,scales="free") +
opts(legend.position = "none") + coord_trans(y = "sqrt")
这篇关于ggplot2 barplot处理1个异常值,将轴向上推的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!