簡體   English   中英

如何使用 ggplot2 繪制分類變量?

[英]How to plot a categorical variable using 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

再次:請展示您下次嘗試過的內容,以及使用dput的數據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~.)

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM