R ggplot2避免绘制点
我正在使用ggplot2创建点打印。我的数据基本上是三列形式的x_轴、y_轴和z_轴,x_轴和y_轴一起表示一对,z_轴表示对计数 所以我画了x_轴和y_轴,用z_轴给点上色。 在某些情况下,我希望跳过绘制特定计数,例如:计数1多次出现,有时我希望跳过绘制1,但图例应显示1。以下是我的代码:R ggplot2避免绘制点,r,ggplot2,R,Ggplot2,我正在使用ggplot2创建点打印。我的数据基本上是三列形式的x_轴、y_轴和z_轴,x_轴和y_轴一起表示一对,z_轴表示对计数 所以我画了x_轴和y_轴,用z_轴给点上色。 在某些情况下,我希望跳过绘制特定计数,例如:计数1多次出现,有时我希望跳过绘制1,但图例应显示1。以下是我的代码: > new<-read.table("PB1_combo.txt", header=T, sep="\t") > bp <-ggplot(data=new, aes(
> new<-read.table("PB1_combo.txt", header=T, sep="\t")
> bp <-ggplot(data=new, aes(x_axis,y_axis, colour=factor(z_axis)), size=z_axis) +
geom_point(size=5)
> bp + ggtitle("PB1-PB1")
> last_plot()+ scale_colour_discrete(name="Counts")
> last_plot()+ theme_bw()
Sample data from PB1_combo.txt
x_axis y_axis z_axis
14 576 2
394 652 2
759 762 2
473 762 2
65 763 3
114 390 2
762 763 4
758 762 2
388 616 2
217 750 2
65 762 2
473 763 2
743 759 2
65 213 2
743 762 2
>新bp bp+ggtitle(“PB1-PB1”)
>最后一个绘图()+比例、颜色、离散(name=“Counts”)
>最后一个图()+主题图()
来自PB1_combo.txt的示例数据
x_轴y_轴z_轴
14 576 2
394 652 2
759 762 2
473 762 2
65 763 3
114 390 2
762 763 4
758 762 2
388 616 2
217 750 2
65 762 2
473 763 2
743 759 2
65 213 2
743 762 2
首先,您应该创建一个系数z_轴
。这样,即使不是所有可能的值都存在,R也会意识到它们
new$Count <- factor(new$z_axis)
实际上,请参见。请提供示例数据,说明您的问题。我们没有
PB1\u combo.txt
。最好的方法是模拟一些东西并发布代码,或者发布dput(head(new))
。这两种方法都有描述。如果你不清楚如何用数据写一个问题,请阅读《佩顿:似乎是完美的解决方案》。
ggplot(data=new[new$Count!="2", ], aes(x_axis,y_axis, colour=Count), size=z_axis) +
geom_point(size=5) +
ggtitle("PB1-PB1") +
scale_colour_discrete(name="Counts", drop=FALSE) +
theme_bw()