简体   繁体   中英

Show box plot of one column against values from another column as x axis

I have data that looks as follows

"","Speaker","Total"
"1","David",19
"2","Grimes",29

I am looking to create a box plot in R as follows在此处输入图像描述

I am able to create a box plot as follows

df = read.csv('C:\\abovefile.csv')
barplot(df$Total, main="Total v/s Speaker",xlab="Speaker name")

However, I wasn't able to figure out how to show the name of the speaker at the bottom of each bar. How can I do this in R?

My graph currently looks like this在此处输入图像描述

Use the names argument in barplot:

df <- tibble(
    x = c("1","2"),
    Speaker = c("David", "Grimes"),
    Total = c(19,29)
)

barplot(df$Total, main="Total v/s Speaker",xlab="Speaker name",
        names = df$Speaker)

在此处输入图像描述

You can try this:

library(ggplot2)
#Plot
ggplot(data,aes(x=Speaker,y=Total))+
  geom_bar(stat = 'identity',color='black',fill='blue')

在此处输入图像描述

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