Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GGR中一个绘图的多个图例_R_Ggplot2 - Fatal编程技术网

GGR中一个绘图的多个图例

GGR中一个绘图的多个图例,r,ggplot2,R,Ggplot2,我见过现有的踏板,但我无法更正我的代码。我必须将图例“分段”分为两个不同的图例。一个图例应显示(跑步、步行),另一个图例应显示静止点(是、否)。问题是,所有图例值都会混淆,并位于同一图例标题下。有人能告诉我这件事吗?谢谢大家! ll_meanstt <- sapply(total_trajectory[1:2], mean) sq_map2tt <- get_map(location = ll_meanstt, maptype = "roadmap", source

我见过现有的踏板,但我无法更正我的代码。我必须将图例“分段”分为两个不同的图例。一个图例应显示(跑步、步行),另一个图例应显示静止点(是、否)。问题是,所有图例值都会混淆,并位于同一图例标题下。有人能告诉我这件事吗?谢谢大家!

   ll_meanstt <- sapply(total_trajectory[1:2], mean)
   sq_map2tt <- get_map(location = ll_meanstt,  maptype = "roadmap", source 
   = "google", zoom = 21)
  sisquoctt <- 
  setNames(data.frame(total_trajectory$tt_lon,total_trajectory$tt_lat, 
  total_trajectory$tt_ids, total_trajectory$Trajectory_Segmentation, 
  total_trajectory$tt_speed, Staypoint), c("lon", "lat", "LocationID", 
  "Segmentation", "SpeedMetersPerSecond", "Staypoint"));



ggmap(sq_map2tt) + 
geom_point(data = sisquoctt, size = 12,  aes(fill = Staypoint, shape = 
Staypoint)) +

geom_point(data = sisquoctt, size = 8,  aes(fill = Segmentation, shape = 
Segmentation)) +

geom_line(data = sisquoctt, size = 3,  aes(color =SpeedMetersPerSecond)) +
geom_label_repel (data = sisquoctt, aes(label = paste("", 

as.character(LocationID), sep="")), 
                  angle = 60, hjust = 2, color = "indianred3",size = 4)

        lon      lat    LocationID Segmentation SpeedMetersPerSecond Staypoint
  1  5.010633 47.29399      W5232         Walk                  1.2        No
  2  5.010643 47.29400      W5769         Walk                  1.0       Yes
  3  5.010716 47.29398      W5234          Run                  1.5        No

ll_意味着stt问题在于,对于相同x、y位置的数据,您已经调用了两次
geom_point()
,并为静止点和分段指定了相同的美学(填充和形状),因此ggplot将它们放在同一个图例中。如果为一个变量指定
fill=
,为另一个变量指定
shape=
,则它们应该进入不同的图例中。此外,并非所有点都具有
填充
美学效果,您需要选择具有美学效果的形状(形状21-25具有
填充
),或者使用
颜色=
,这是所有ggplot2点都具有的美学效果

使用
color
代替
fill

ggmap(sq_map2tt) + 
geom_point(data = sisquoctt, size = 8,  aes(color = Staypoint, shape = Segmentation)) + 
geom_line(data = sisquoctt, size = 3,  aes(color = SpeedMetersPerSecond))
如果要使用
填充
而不是
颜色

ggmap(sq_map2tt) + 
    geom_point(data = sisquoctt, size = 8,  aes(fill = Staypoint, shape = Segmentation)) + 
    scale_shape_manual(values = c(21, 24) +
    geom_line(data = sisquoctt, size = 3,  aes(color = SpeedMetersPerSecond))

问题是,对于相同x、y位置的数据,您已经调用了两次
geom_point()
,并将相同的美学(填充和形状)分配给了静止点和分段,因此ggplot将它们放在同一个图例中。如果为一个变量指定
fill=
,为另一个变量指定
shape=
,则它们应该进入不同的图例中。此外,并非所有点都具有
填充
美学效果,您需要选择具有美学效果的形状(形状21-25具有
填充
),或者使用
颜色=
,这是所有ggplot2点都具有的美学效果

使用
color
代替
fill

ggmap(sq_map2tt) + 
geom_point(data = sisquoctt, size = 8,  aes(color = Staypoint, shape = Segmentation)) + 
geom_line(data = sisquoctt, size = 3,  aes(color = SpeedMetersPerSecond))
如果要使用
填充
而不是
颜色

ggmap(sq_map2tt) + 
    geom_point(data = sisquoctt, size = 8,  aes(fill = Staypoint, shape = Segmentation)) + 
    scale_shape_manual(values = c(21, 24) +
    geom_line(data = sisquoctt, size = 3,  aes(color = SpeedMetersPerSecond))

不要将您的数据发布为图像,请学习如何发布我已更新的问题:)不要将您的数据发布为图像,请学习如何发布我已更新的问题:)