需要帮助对数据进行分类(基于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)
哇!这正是我想要的。它成功了。非常感谢!:)我还想显示条上每个部分的好或坏的数量。我该怎么做?谢谢