合并r中具有相同行名称的2个数据帧

合并r中具有相同行名称的2个数据帧,r,dataframe,plot,merge,row-number,R,Dataframe,Plot,Merge,Row Number,我有2个数据帧,我想将它们合并成一个数据帧,每个数据帧对应于彼此的行名称值。如果您能告诉我如何在绘图(ggplot2或绘图)上绘制它们,我将不胜感激 df1: df2: 使用merge,我们可以使用by作为行。名称 out <- merge(df1, df2, by = 'row.names') 或使用tidyverse library(ggplot2) library(dplyr) library(tidyr) merge(df1, df2, by = 'row.names') %&

我有2个数据帧,我想将它们合并成一个数据帧,每个数据帧对应于彼此的行名称值。如果您能告诉我如何在绘图(ggplot2或绘图)上绘制它们,我将不胜感激


df1:

df2:


使用
merge
,我们可以使用
by
作为
行。名称

out <- merge(df1, df2, by = 'row.names')
或使用
tidyverse

library(ggplot2)
library(dplyr)
library(tidyr)
merge(df1, df2, by = 'row.names') %>% 
   rename(nm = 'Row.names') %>%  # // rename the column name
   type.convert(as.is = TRUE) %>%  # // some columns were not of the correct type
   pivot_longer(cols = -nm) %>% # // reshape to 'long' format
   ggplot(aes(x = name, y = value, fill = nm)) + # // plot as bar
        geom_col() + 
        theme_bw()
-输出


我在考虑更多的散点图,但感谢合并部分。
out <- merge(df1, df2, by = 'row.names')
barplot(`row.names<-`(as.matrix(out[-1]),
          out$Row.names), col = c('blue', 'green', 'red'), legend = TRUE)
library(ggplot2)
library(dplyr)
library(tidyr)
merge(df1, df2, by = 'row.names') %>% 
   rename(nm = 'Row.names') %>%  # // rename the column name
   type.convert(as.is = TRUE) %>%  # // some columns were not of the correct type
   pivot_longer(cols = -nm) %>% # // reshape to 'long' format
   ggplot(aes(x = name, y = value, fill = nm)) + # // plot as bar
        geom_col() + 
        theme_bw()