簡體   English   中英

如何將列用作x軸

[英]How to use the columns as x-axis

我很難創建一個簡單的圖。 我准備了一些數據作為要繪制的示例:

m.alphabet_summary <-
structure(c(194L, 185L, 208L, 219L, 194L, 161L, 205L, 219L, 188L, 
227L, 210L, 189L, 196L, 213L, 192L, 207L, 220L, 203L, 181L, 189L, 
221L, 192L, 189L, 205L, 193L, 188L, 187L, 209L, 189L, 227L, 213L, 
200L, 206L, 194L, 187L, 184L, 209L, 223L, 198L, 186L, 183L, 232L, 
191L, 190L, 204L, 209L, 178L, 203L, 184L, 226L), .Dim = c(5L, 
10L), .Dimnames = list(c("As", "Bs", "Cs", "Ds", "Os"), NULL))

#   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#As  194  161  210  207  221  188  213  184  183   209
#Bs  185  205  189  220  192  187  200  209  232   178
#Cs  208  219  196  203  189  209  206  223  191   203
#Ds  219  188  213  181  205  189  194  198  190   184
#Os  194  227  192  189  193  227  187  186  204   226

我想將Y軸作為單元格中的值(范圍在200左右的值),而x軸應作為列號(范圍為1-10)。 分組/顏色應根據列名(a,b,c,d,o)

非常感謝您的任何建議!

我將使用ggplot,並跳過大部分數據處理-ggplot會解決這一問題。

sampling <- c("o", "b", "c", "d", "a")
alphabet <- sample(sampling, 10000, replace = TRUE)
group <- factor(rep(1:10, each = 1000))
df <- data.frame(group, alphabet)

library(ggplot2)
ggplot(df, aes(x = group, fill = alphabet)) + 
  geom_bar(position = "dodge")

暫無
暫無

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

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