簡體   English   中英

如何在 R 中創建具有非連續變量的條形圖?

[英]how can i create bar chart with non continuous variable in R?

Names=c(1,2,3,4,5,6,7,8)
Series= c(19.5,18.5,11,13,1,5,6,6)
df=c(Names,Series)

ggplot(df,aes(x= Names,y=Series))+geom_col(position="identity",fill="red")

但我不知道如何使名稱成為 x 軸,因為它顯示 x 軸 0、2.5、5、... 1、2、3、4、5 的奇怪圖形,不是連續變量,而是一個指標 I需要 x 軸為名稱,y 軸為系列我需要 x 軸為 Names show 1,2,3,4 ... rand y 軸為 Series

你應該做什么:

ggplot(mapping = aes(x = factor(Names), y = Series)) + 
    geom_col(position="identity",fill="red")

在此處輸入圖像描述

暫無
暫無

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

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