R 分组条形图

R 分组条形图,r,plot,R,Plot,我在R中有一个数据帧数据,看起来像 construct category count 0 insert 327 1 insert 320 2 insert 311 3 insert 309 4 insert 297 0 rev_insert 216 1 rev_insert 214 2 rev_insert 211 3 re

我在R中有一个数据帧数据,看起来像

construct       category        count
0       insert  327
1       insert  320
2       insert  311
3       insert  309
4       insert  297
0       rev_insert      216
1       rev_insert      214
2       rev_insert      211
3       rev_insert      220
4       rev_insert      228
我想为每个构造制作一个数据$counts的分组条形图,每个类别“insert”和“rev_insert”有两个条形图

试试这个:

# dummy data
df <- read.table(text="construct       category        count
0       insert  327
1       insert  320
2       insert  311
3       insert  309
4       insert  297
0       rev_insert      216
1       rev_insert      214
2       rev_insert      211
3       rev_insert      220
4       rev_insert      228", header=TRUE)

library(ggplot2)
# plot
ggplot(df,aes(construct,count,fill=category)) +
   geom_bar(stat="identity",position="dodge")
#虚拟数据
df试试这个:

# dummy data
df <- read.table(text="construct       category        count
0       insert  327
1       insert  320
2       insert  311
3       insert  309
4       insert  297
0       rev_insert      216
1       rev_insert      214
2       rev_insert      211
3       rev_insert      220
4       rev_insert      228", header=TRUE)

library(ggplot2)
# plot
ggplot(df,aes(construct,count,fill=category)) +
   geom_bar(stat="identity",position="dodge")
#虚拟数据
df