简体   繁体   English

将一列的框 plot 与另一列的值显示为 x 轴

[英]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我正在寻找在 R 中创建一个框 plot 如下在此处输入图像描述

I am able to create a box plot as follows我能够创建一个盒子 plot 如下

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?如何在 R 中执行此操作?

My graph currently looks like this我的图表目前看起来像这样在此处输入图像描述

Use the names argument in barplot:在 barplot 中使用 names 参数:

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

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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