R 带有数据帧标头的条形图或ggplot

R 带有数据帧标头的条形图或ggplot,r,ggplot2,R,Ggplot2,我想获得一个ggplot或一个以数据帧的头作为该条图x的条图 colSums.df4..na.rm...TRUE. 11+12 149 11+13 59 11+2 74 11+20 7 11+23

我想获得一个ggplot或一个以数据帧的头作为该条图x的条图

                              colSums.df4..na.rm...TRUE. 
11+12                          149
11+13                           59
11+2                            74
11+20                            7
11+23                          118
我想获得一个ggplot,标题(11+12,11+13…)为x,“colSums.df4..na.rm…TRUE”为y


提前谢谢。

试试这种方法。使用
rownames\u to_column()
将rownames作为一个新变量传输到列(),然后为了练习的目的更改该长名称。这里的代码使用了一些
tidyverse
函数和
ggplot2

library(tidyverse)
#Code
df %>% rownames_to_column('Var') %>%
  rename(Value=colSums.df4..na.rm...TRUE.) %>%
  ggplot(aes(x=Var,y=Value))+
  geom_bar(stat='identity',color='black',fill='magenta')+
  theme_bw()
输出:

使用的一些数据:

#Data
df <- structure(list(colSums.df4..na.rm...TRUE. = c(149L, 59L, 74L, 
7L, 118L)), class = "data.frame", row.names = c("11+12", "11+13", 
"11+2", "11+20", "11+23"))
#数据

df请共享可复制的示例
dput(mydata)
。尝试以下操作:
barplot(mtcars[,“cyl”],names.arg=rownames(mtcars))