【问题标题】:data frame in r with plot bar and datar中的数据框,带有绘图栏和数据
【发布时间】:2021-03-19 19:45:18
【问题描述】:

非常感谢您对这个问题的帮助

下面的数据框“df”生成条形图。

项目编号年份 2014 年 400 人 b 150 2015 c 300 2011 300 2015 c 400 2011 c 100 2011 b 250 2014

完成以下代码生成下面的条形图

newdf %

(数字 = 数字/100) %>% group_by(

) %>%

(m = 中位数( ))

This is the bar plot

【问题讨论】:

    标签: r dataframe plot


    【解决方案1】:

    试试这个:

    library(ggplot2)
    library(dplyr)
    #Code
    df %>%
      mutate(number = number/100) %>%
      group_by(item)%>%
      summarise(m = median(number)) %>%
      ggplot(aes(x=item,y=m))+
      geom_bar(stat = 'identity')
    

    输出:

    使用的一些数据:

    #Data
    df <- structure(list(item = c("a", "b", "c", "a", "c", "c", "b"), number = c(400L, 
    150L, 300L, 300L, 400L, 100L, 250L), year = c(2014L, 2015L, 2011L, 
    2015L, 2011L, 2011L, 2014L)), class = "data.frame", row.names = c(NA, 
    -7L))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多