如何从 ggplot2 包中仅绘制 geom_point 中的一系列值?

发布于 2024-09-19 17:42:54 字数 991 浏览 8 评论 0原文

alt text大家好, 我有以下熔融数据:

 X      variable       value    
1 StationA SAR11.cluster 0.001309292
2 StationB SAR11.cluster 0.002712237
3 StationC SAR11.cluster 0.002362708
4 StationD SAR11.cluster 0.002516751
5 StationE SAR11.cluster 0.004301075
6 StationF SAR11.cluster 0.0

.
.
.
etc.
etc.

我使用以下代码绘制了数据的气泡图:

ggplot(foomelt, aes(x=foomelt$Station, y=variable, angle=45, size=(value))) + 
+geom_point() +  opts(theme_bw(), axis.text.x = theme_text(size=10, angle = 70)) 
+ scale_area()

一切都很好,只是我想忽略 0(零)值并且仅用于缩放所有这些值之间的点值大于零和最大值。 我不想从数据中删除零值行,因为为了证明一点,我希望包含所有站和变量,并将零值的那些留空。

我设法使用它来忽略零值,但缩放不起作用:

   ggplot(foomelt, aes(x=foomelt$Station, y=variable, angle=45, size=(value>0))) +
    + geom_point() +  opts(theme_bw(), axis.text.x = theme_text(size=10, angle = 70)) 
    + scale_area("Ratio") + scale_size_identity()

任何帮助将不胜感激。

alt textHello All,
I have the following molten data:

 X      variable       value    
1 StationA SAR11.cluster 0.001309292
2 StationB SAR11.cluster 0.002712237
3 StationC SAR11.cluster 0.002362708
4 StationD SAR11.cluster 0.002516751
5 StationE SAR11.cluster 0.004301075
6 StationF SAR11.cluster 0.0

.
.
.
etc.
etc.

I used the following code to chart a bubblechart of the data:

ggplot(foomelt, aes(x=foomelt$Station, y=variable, angle=45, size=(value))) + 
+geom_point() +  opts(theme_bw(), axis.text.x = theme_text(size=10, angle = 70)) 
+ scale_area()

All is well except that I want to ignore the 0 (zero) values and only use for the scaling of the dots values between all those that are grater than zeroes and the max value.
I don't want to delete the zero values rows from the data because in order to prove a point I want all the stations and variables to be included and to have those with the zero value left blank.

I managed to use this to ignore the zero values but scaling does not work:

   ggplot(foomelt, aes(x=foomelt$Station, y=variable, angle=45, size=(value>0))) +
    + geom_point() +  opts(theme_bw(), axis.text.x = theme_text(size=10, angle = 70)) 
    + scale_area("Ratio") + scale_size_identity()

any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

信愁 2024-09-26 17:42:54

我不确定这是否是您正在寻找的,但在绘制点时忽略零值的一种方法是将 geom_point() 语句修改为该

geom_point(subset = .(value > 0))

行仅传递要绘制的数据框中的非零值。

i am not sure if this is what you are looking for, but one approach to ignore the zero values while plotting the points is to modify your geom_point() statement to

geom_point(subset = .(value > 0))

this line passes only the non zero values in the data frame to be plotted.

嘴硬脾气大 2024-09-26 17:42:54

只是为了展示我如何使用 Ramnath(谢谢!)的建议(以便帮助像我这样的新手):

foo= read.csv('~/Desktop/foo.csv', header=T)
foomelt = melt(foo)
foomelt$Station<-factor(foomelt$Station, levels=unique(as.character(foo[[1]]))) #to keep the order of the x axis the same
                                                                                # as in the original file`
bigfoo <- subset(foomelt, value > 0) #use only those values that are larger than 0
ggplot(bigfoo, aes(x=bigfoo$Station, y=variable, angle=45, size=(value))) +  geom_point() 
+  opts(theme_bw(), axis.text.x   = theme_text(size=9, angle = 90)) + scale_area()

Just to show how I used Ramnath's (thanks!) suggestions (so to help novices like myself):

foo= read.csv('~/Desktop/foo.csv', header=T)
foomelt = melt(foo)
foomelt$Station<-factor(foomelt$Station, levels=unique(as.character(foo[[1]]))) #to keep the order of the x axis the same
                                                                                # as in the original file`
bigfoo <- subset(foomelt, value > 0) #use only those values that are larger than 0
ggplot(bigfoo, aes(x=bigfoo$Station, y=variable, angle=45, size=(value))) +  geom_point() 
+  opts(theme_bw(), axis.text.x   = theme_text(size=9, angle = 90)) + scale_area()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文