2015-12-22 284 views
-4

這裏是我用來生成我的數字的數據。現在,我想根據土地使用類型使用這些數據生成一個方面。是否有可能這樣做。任何人都可以給我一些建議嗎?謝謝。如何使用ggplot2繪製分類變量?

Variables Cropland Forest Shrub Urban Water Baresoil MeanDecreaseAccuaracy MeanDecreaseGini 
band1 23.152 14.686 30.012 26.866 12.976 9.767 33.991 142.946 
band2 23.359 19.116 30.077 23.961 14.12 11.793 32.729 165.892 
band3 24.835 21.59 17.912 18.49 14.806 23.961 32.254 169.372 
band4 25.709 34.052 20.737 23.17 13.894 25.297 36.721 209.631 
band5 20.158 29.281 24.762 25.535 18.537 14.182 36.525 141.047 
band6 32.447 25.134 24.8 35.59 22.485 16.168 40.496 232.536 
band7 26.135 41.411 36.753 26.935 19.767 9.806 39.886 226.782 
band8 2.46 1.93 1.872 -0.434 -0.088 4.831 4.315 5.334 
+1

對於未來的問題,請使用'''dput()'''包括您的數據(雖然樣品感激!),也表明你想要做的一個嘗試。 – Nancy

+1

對不起。因爲有一些規則我還不明白。 – JimmyGao

回答

1

再次:請出示你試了一下下一次,使用dput數據的樣本沿。

請注意,我將數據融合爲長格式,然後使用「變量」作爲構面。如果您想橫向嘗試facet_grid(.~ variable),那麼點只表示「其他」,而〜表示「方面」。

df = melt(df, id.vars = c("Variables")) 

>head(df) 
Variables variable value 
    band1 Cropland 23.152 
    band2 Cropland 23.359 
    band3 Cropland 24.835 
    band4 Cropland 25.709 
    band5 Cropland 20.158 
    band6 Cropland 32.447 

ggplot(df) + 
    geom_point(aes(x = Variables, y = value)) + 
    facet_grid(variable~.) 

enter image description here