开发者

How to draw only a range of values in geom_point from the ggplot2 package?

开发者 https://www.devze.com 2023-01-16 00:53 出处:网络
Hello All, I have the following molten data: Xvariablevalue 1 StationA SAR11.cluster 0.001309292 2 StationB SAR11.cluster 0.002712237

How to draw only a range of values in geom_point from the ggplot2 package?

Hello 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 f开发者_如何学Pythonor 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.


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.


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()
0

精彩评论

暂无评论...
验证码 换一张
取 消