df
fd

你好,

从所附的2个数据集,我想根据代码列在同一页上绘制2个图形
x轴是年份,y轴是数值。

值列在两个数据集中是不同的,我想有两个图形
任何帮助吗?

1像

记住要举一个可重复的例子。
我得到的数据OCR在R

df <结构(列表(年= 2000:2010代码= c (129 l、129 l、129 l、129 l、129 l、129 l、129 l、129 l、129 l、129 l、129 l),价值= c(34岁的12 0 l, l, 23 l l 0 l、89 l、67 l, l (0, 0 l, l, 45 23 l)),类=“data.frame row.names = c (NA, -11 l)) # 129年代码值# 1 2000 0 # 2 2001 129 12 # 23 # 4 3 2002 129 2003 129 34 # 5 2004 129 0 # 2005 129 89 6 # 7 # 8 2006 129 67 2007 129 0 # 9 2008 129 0 45 # 11 # 2009 129 2010 129 23 p1 < - ggplot (df, aes (x =, y =值)+ geom_point() #点

df2 <- structure(list(year = 2000:2010, code = c(129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 129L, 99L, 67L, 0L, 0L, 70L, 0L)), class = "data.frame", row.names = c(NA, - 11l)) p2 <- ggplot(df2, aes(x=year, y=value)) + geom_point() # for points

库(gridExtra)库(grid)网格。安排(p1,p2, ncol=1, top=textGrob(“多个地块”,gp=gpar(fontsize=12, font = 2))))

1像

或者,您可以合并这两个数据帧并使用facet_wrap ().下面是一个使用@M_AcostaCH数据帧。

库(tidyverse) df <结构(列表(年= 2000:2010代码= c (129 l、129 l、129 l、129 l、129 l、129 l、129 l、129 l、129 l、129 l、129 l),价值= c(34岁的12 0 l, l, 23 l l 0 l、89 l、67 l, l (0, 0 l, l, 45 23 l)),类=“data.frame row.names = c (NA, -11 l)) df2 < -结构(列表(年= 2000:2010代码= c (129 l、129 l、129 l、129 l、129 l、129 l、129 l、129 l、129 l、129 l、139 l),价值= c (23 l 0 l 13 l, l (0, 0 l、99 l、67 l, l (0, 0 l、70 l, 0 l)),类=“data.frame row.names = c (NA, -11 l)) df % > % left_join (df2,By = c("year", "code")) %>% pivot_long (cols=value.x:value.y) %>% ggplot(aes(x = factor(year), y =value)) + geom_point(show. y =value))= F) + facet_wrap(~ name, nrow = 2)

本主题在最后一次回复后42天自动关闭。新的回复不再被允许。

如果你有一个与它或其中一个回复相关的查询,开始一个新的主题,并返回一个链接。