Вот способ построить стрелки. Используйте geom_segment
, аргумент arrow
, обращая внимание на настройки arrow(length, unit)
.
library(ggplot2)
g <- ggplot(fires, aes(x = THREATEN_1, y = Total_area, color = THREATEN_1)) +
geom_point() +
labs(x = "Threatened status", y = "Extent of suitable habitat (Ha)")
g + geom_segment(aes(xend = THREATEN_1, yend = Area_remai),
arrow = arrow(length = unit(0.025, "npc"))) +
scale_color_manual(values = c("indianred", "dodgerblue")) +
theme_bw() +
theme(legend.position = "none") +
facet_wrap(~ THREATEN_1, scales = "free_x")
jitter
данные.
Приведенный выше код превзойдет стрелки в вопросе, который задают для дрожания набора данных.
library(dplyr)
set.seed(1234)
fires %>%
group_by(THREATEN_1) %>%
mutate(THREATEN_1b = jitter(as.numeric(THREATEN_1), amount = 0.3/2)) %>%
ggplot(aes(x = THREATEN_1b, y = Total_area, color = THREATEN_1)) +
geom_point(aes(color = THREATEN_1), alpha = 0.25) +
labs(x = "Threatened status", y = "Extent of suitable habitat (Ha)") -> g
g + geom_segment(aes(xend = THREATEN_1b, yend = Area_remai),
arrow = arrow(length = unit(0.025, "npc"))) +
scale_color_manual(values = c("indianred", "dodgerblue")) +
theme_bw() +
theme(legend.position = "none",
axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
facet_wrap(~ THREATEN_1, scales = "free_x")
Данные.
fires <- read.table(text = "
species THREATEN_1 Total_area Area_remai
a V 30. 10
b EN 100. 50
c V 5. 2
", header = TRUE)