我想制作两个组的散点图,然后添加一个箭头。但我不希望箭头显示在图例条目中或弄乱前面的图例条目。
这是我的例子:
library(tidyverse)
df <- tribble(
~country, ~series1, ~series2,
#--|--|----
"USA", 8, 5,
"USA", 9, 6,
"USA", 11, 7,
"USA", 10, 8,
"USA", 11, 4,
"USA", 14, 10,
"USA", 16, 12,
"USA", 12, 8,
"USA", 12, 13,
"USA", 13, 10,
"USA", 11, 5,
"FRA", 5, 6,
"FRA", 6, 8,
"FRA", 5, 7,
"FRA", 4, 8,
"FRA", 9, 11,
"FRA", 7, 9,
"FRA", 14, 11,
"FRA", 7, 11,
"FRA", 6, 6,
"FRA", 5, 7,
"FRA", 4, 5
)
ggplot(df, aes(x = series1, y = series2, color = country)) +
geom_point() +
geom_segment(aes(x = 4, xend=6, y = 11, yend=8),
arrow = arrow(length = unit(0.5, "cm")))
哪个让我:
以某种方式对图例的显示方式做了些什么(它在那里放了一个奇怪的箭头)。
(我有两个小的后续问题:1)你如何改变箭头的宽度?2)你如何改变箭头的alpha值?)
答案 0 :(得分:1)
只需将show.legend = FALSE
添加到geom_segment
geom即可。 grid::arrow
并未提及任何关于&#34;翅膀&#34;的长度的信息。你将不得不深入研究代码。