首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用我组合的数据为我的散点图着色?

如何用我组合的数据为我的散点图着色?
EN

Stack Overflow用户
提问于 2020-08-25 23:10:31
回答 1查看 30关注 0票数 1

我有两个数据集(我最终将使用八个),我已经将它们组合在一起创建了散点图。问题是,现在我已经绘制了散点图,我不知道如何分离我组合的数据,以便颜色表示单独的数据集。这是我的代码。

代码语言:javascript
复制
#Here is what I've combined:

    t<-rbind(test202, test342)

#Here is plotting the scatter-plot 

    ```{r}
    g<-ggplot(t,aes(x=percentage,y=as.numeric(area), col = area, group = area ))+
      geom_point()+
  labs(x=expression(paste("Percentage (%)")),
       y=expression(paste("Area (m"^2,")"))
       )+
  scale_y_continuous(breaks = seq(0, 20, by = 1)) +
  theme_bw() +
  theme(element_blank())
g
``

我试过用谷歌搜索这个问题,但似乎找不到任何特定的代码来修复这个问题。我附上了一张最终产品和内容的图片。contents of 't' scatter-plot of 't'

编辑: dput(t)

代码语言:javascript
复制
t <- structure(list(percentage = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 
    7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 
    7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L), .Label = c("30", "35", 
    "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", 
    "95"), class = "factor"), area = c(1.0068507612755, 1.28144642344154, 
    1.55604208560758, 1.92216963516231, 2.28829718471704, 2.65442473427176, 
    3.20361605860385, 3.75280738293594, 4.39353059465671, 5.30884946854352, 
    6.49876400459638, 7.96327420281528, 10.068507612755, 13.6382512209135, 
    1.12935650675177, 1.4004020683722, 1.67144762999262, 1.98766745188312, 
    2.34906153404369, 2.75562987647432, 3.16219821890496, 3.65911508187574, 
    4.15603194484652, 4.74329732835744, 5.37573697213844, 6.18887365699971, 
    7.22788164321134, 8.89932927320397)), row.names = c(NA, -28L), class = "data.frame")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-26 00:10:13

看起来,当您将行rbind在一起时,您只是失去了对数据源的跟踪。由于您说您有更多的dfs要加入,因此我将提供一个dplyr解决方案。

代码语言:javascript
复制
library(dplyr)
library(ggplot2)

t <- dplyr::bind_rows(list(test202 = test202,
                           test342 = test342),
                      .id = 'source')

ggplot(t, aes(x = percentage,
              y = as.numeric(area),
              col = source,
              group = source ))+
   geom_point()+
   labs(x = expression(paste("Percentage (%)")),
        y = expression(paste("Area (m"^2,")"))
   )+
   scale_y_continuous(breaks = seq(0, 20, by = 1)) +
   theme_bw() +
   theme(element_blank())

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63581893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档