简体   繁体   中英

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

but i have no idea how to make Names to be x-axis since it show weird graph with x axis 0,2.5,5,... 1,2,3,4,5, is not a continuous variable but an indicator I need x axis to be Names and y axis to be Series我需要 x 轴为 Names show 1,2,3,4 ... rand y 轴为 Series

What you should do:

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM