我有两个数据集(我最终将使用八个),我已经将它们组合在一起创建了散点图。问题是,现在我已经绘制了散点图,我不知道如何分离我组合的数据,以便颜色表示单独的数据集。这是我的代码。
#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)
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")发布于 2020-08-26 00:10:13
看起来,当您将行rbind在一起时,您只是失去了对数据源的跟踪。由于您说您有更多的dfs要加入,因此我将提供一个dplyr解决方案。
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())

https://stackoverflow.com/questions/63581893
复制相似问题