2010-09-12 55 views
1

alt text您好所有, 我有以下熔融數據:如何從ggplot2包中僅繪製geom_point中的一系列值?

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. 

我用下面的代碼以圖表的數據的BubbleChart中:

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

任何幫助,將不勝感激。

回答

7

我不知道如果這是你在找什麼,但一個方法忽略零個值而繪製的點是修改geom_point()語句

geom_point(subset = .(value > 0)) 

此行只有通行證要繪製的數據幀中的非零值。 (!感謝)

+0

工作!謝謝。 – 2010-09-13 09:57:49

+0

@ Schrodinger'sCat請接受這個答案! – plaes 2012-01-17 18:15:34

+0

你將如何使用這個子集函數來處理非數字值,例如列條目爲狗的列動物。 – KLDavenport 2013-01-02 21:41:33

-1

只是爲了展示如何使用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()