【问题标题】:How exclude columns from different dataframe and then mix two of these columns?如何从不同的数据框中排除列,然后混合其中的两个列?
【发布时间】:2021-01-14 14:07:40
【问题描述】:

我正在尝试从两个不同的数据框中排除列,然后绘制这个不同的数据框(仅绘制数值)。 数据框示例在这里(链接):

enter image description here

enter image description here

我只需要绘制列“Val1”与“Val_1”的值 我在 RStudio 中使用 ggplot2 和 tidyverse,我的列有 727 个“标识名称”(Id1 和 Id2,请参见图片)和各自的值。

这样做的目的是用于散点图,其中 X 轴用于“Val1”,Y 轴用于“Val_1”。 欢迎任何帮助,谢谢! 最好的

【问题讨论】:

  • 请添加一些可以复制的示例数据和可以尝试的代码。

标签: r ggplot2 plot tidyverse


【解决方案1】:

首先将图片转换为样本数据

> dput(df1)
structure(list(Id1 = c("QJY77946", "QJY77954", "QJY77954", "QJY77962", 
"QJY77962"), Id2 = c("NP_073551", "NP_073551", "QJY77946", "NP_073551", 
"QJY77946"), Val1 = c(0.0241, 0.0119, 0.0119, 0.0119, 0.0119)), class = "data.frame", row.names = c(NA, 
-5L))

> dput(df2)
structure(list(ID_1 = c("QJY77946", "QJY77954", "QJY77954", "QJY77962"
), Id_2 = c("NP_073551", "NP_073551", "QJY77946", "NP_073551"
), Val_1 = c(0.1402, 0.0912, 0.0439, 0.0912)), class = "data.frame", row.names = c(NA, 
-4L))

> df1
       Id1       Id2   Val1
1 QJY77946 NP_073551 0.0241
2 QJY77954 NP_073551 0.0119
3 QJY77954  QJY77946 0.0119
4 QJY77962 NP_073551 0.0119
5 QJY77962  QJY77946 0.0119

> df2
      ID_1      Id_2  Val_1
1 QJY77946 NP_073551 0.1402
2 QJY77954 NP_073551 0.0912
3 QJY77954  QJY77946 0.0439
4 QJY77962 NP_073551 0.0912

你可以试试这个

df1 %>% inner_join(df2, by = c("Id1"="ID_1", "Id2"="Id_2")) %>% ggplot() +
  geom_point(aes(x = Val1, y=Val_1))

【讨论】:

    猜你喜欢
    • 2018-06-26
    • 1970-01-01
    • 2021-11-20
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 2021-01-06
    • 2018-03-30
    • 1970-01-01
    相关资源
    最近更新 更多