楼主: 子衿1219
2734 6

[问答] ggplot2不同数据集合并 [推广有奖]

  • 1关注
  • 4粉丝

讲师

70%

还不是VIP/贵宾

-

威望
0
论坛币
60 个
通用积分
1.0023
学术水平
2 点
热心指数
0 点
信用等级
1 点
经验
13521 点
帖子
326
精华
0
在线时间
431 小时
注册时间
2012-3-19
最后登录
2018-7-8

楼主
子衿1219 发表于 2016-9-25 14:19:54 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
如下做用ggplot2做p1,p2,不同的数据集,问如何将两幅图合并到一张图中,并且将legend合并。

a <-c(0.61,0.57,0.78,1.36,0.85,0.53,0.45,0.19,0.08) #names
b <-c(0.23,0.26,0.55,0.56,0.36,0.23,0.18,0.06,0.04) #mean t0
x <-c(0.64,0.6,0.81,1.4,0.89,0.55,0.48,0.22,0.09) #mean t1

       
da <- data.frame(a,b,x)
da1 <- melt(test_data56, id="x")
p0 <- ggplot(data=da1 , aes(x=x,
   y=value,group=variable,linetype=variable,color=variable, shape=variable)) + geom_line()


x1<- c(0.81,0.81)
y1<-c(0.5,0.8)
da2 <- data.frame(x1,y1)
p1<-ggplot()+geom_point(data=da2,aes(x=x1,y=y1, colour = c("blue","red")),size=c(3,3))

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:ggplot2 gplot plot GPL 数据集 legend 如何

沙发
子衿1219 发表于 2016-9-25 14:28:12
是p0和p1......

藤椅
johnmy 发表于 2016-9-25 16:49:10
test_data56是什么,da?

板凳
johnmy 发表于 2016-9-25 18:46:59
ggplot()+geom_line(data=da1,aes(x=x,y=value,group=variable,linetype=variable,color=variable, shape=variable))+geom_point(data=da2,aes(x=.81,y=c(.5,.8),color=as.factor(y1)),size=3)

图例再想办法 改吧

报纸
johnmy 发表于 2016-9-25 18:57:03
  1. ggplot()+
  2.   geom_line(data=da1,aes(x=x,y=value,group=variable,linetype=variable,color=variable, shape=variable))+
  3.   geom_point(data=da2,aes(x=.81,y=c(.5,.8),color=as.factor(y1)),size=3)+
  4.   scale_color_manual(values = c( "red", "blue", "darkgreen",  "orange"), labels = c("four", "six", "eight","55"))
复制代码

地板
子衿1219 发表于 2016-9-25 20:56:40
johnmy 发表于 2016-9-25 16:49
test_data56是什么,da?
是da,不好意思写错了。。。。。

7
子衿1219 发表于 2016-9-25 21:49:31
johnmy 发表于 2016-9-25 18:57
p1 <- ggplot(data=da1,aes(x=x,y=value,group=variable,linetype=variable,color=variable, shape=variable))+geom_point()+geom_line()
p1+ggplot()+geom_point(aes(x=.81,y=c(.5,.8),color=as.factor(y1)),size=3)+
  scale_color_manual(values = c( "red", "blue", "darkgreen",  "orange"), labels = c("four", "six", "eight","55"))

谢谢您的回答,对我的帮助很大,我略作修改,想先标点,再连线。p1是可以生成的啊,为何后一句报错了呢?

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 00:35