Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要帮助对数据进行分类(基于r中的2列)_R - Fatal编程技术网

需要帮助对数据进行分类(基于r中的2列)

需要帮助对数据进行分类(基于r中的2列),r,R,我有两列-一列有数字(部分),另一列在r 下面是一个示例数据 df使用base-r可以执行以下操作: 条形图(表(df),legend.text=TRUE,next=TRUE,yaxt=“n”,xlab=“Section”,ylab=“Freq”) 轴(2,at=seq(0,3,1),las=1) #如果要堆叠钢筋,可以将next=FALSE设置为。 输出 资料 df我希望您安装了ggplot2软件包,因为ggplot是创建图形的一个很棒的软件包 以下是实现所需功能的代码: library(

我有两列-一列有数字(部分),另一列在
r

下面是一个示例数据


df使用
base-r
可以执行以下操作:

条形图(表(df),legend.text=TRUE,next=TRUE,yaxt=“n”,xlab=“Section”,ylab=“Freq”) 轴(2,at=seq(0,3,1),las=1) #如果要堆叠钢筋,可以将next=FALSE设置为。
输出

资料
df我希望您安装了ggplot2软件包,因为ggplot是创建图形的一个很棒的软件包

以下是实现所需功能的代码:

library(ggplot2)
df <- data.frame("G or B" = c("Good", "Good", "Bad", "Good", "Good", "Bad", "Good", "Good"), 
                 "Section" = c(1,1,1,1,2,2,3,3)  )   # This is your data frame

names(df)  # checking the variable names

ggplot(df, aes(x = Section, fill = G.or.B) )+  # Creates the bar graph with good / bad
    geom_bar() 
库(ggplot2)

哇!这正是我想要的。它成功了。非常感谢!:)我还想显示条上每个部分的好或坏的数量。我该怎么做?谢谢