这似乎是一个基本问题,但我找不到它的解决方案。我有下面提到的数据;
x y group
1 5.010786 47.29396 1
2 5.010719 47.29402 2
3 5.010679 47.29400 3
4 5.010642 47.29399 4
5 5.010862 47.29398 5
6 5.010707 47.29399 6
7 5.010835 47.29396 7
8 5.010823 47.29397 8
9 5.010722 47.29400 9
10 5.010823 47.29397 10
11 5.010722 47.29400 11
12 5.010823 47.29397 12
我正在绘制此数据,但它忽略了绘制的重复值。在上面的数据中有12个数据点。但是下面的图只显示了 9。我需要绘制每个点。任何人都可以告诉我是否可能?其次,有没有办法在绘图时防止四舍五入。(例如;5.01078627407352 不应该像 5.010786)。
代码;
df <- data.frame(x = lon_redc, y = lat_redc, group = 1:12)
g <- ggplot(df, aes(x = x, y = y, color = as.factor(group),label =
group))
g <- g + geom_segment(aes(xend=c(tail(x, n=-1), NA),
yend=c(tail(y, n=-1), tail(y, n = 1))),
arrow=arrow(length = unit(0.7, "cm")))
g <- g + theme_bw() + theme(legend.position="none") +
xlab("longitude") +
ylab("latitude") + geom_text(aes(x = jitter(x), y = jitter(y)),
check_overlap = TRUE, size = 7)
g
问题是你告诉 ggplot2 删除重叠的文本。绘图时没有四舍五入,所以我不知道你在那里指的是什么。
df <- read.table(text =" x y group
1 5.010786 47.29396 1
2 5.010719 47.29402 2
3 5.010679 47.29400 3
4 5.010642 47.29399 4
5 5.010862 47.29398 5
6 5.010707 47.29399 6
7 5.010835 47.29396 7
8 5.010823 47.29397 8
9 5.010722 47.29400 9
10 5.010823 47.29397 10
11 5.010722 47.29400 11
12 5.010823 47.29397 12", header = TRUE)
g <- ggplot(df, aes(x = x, y = y, color = as.factor(group),label =
group)) +
geom_segment(data = cbind(head(df, -1),
xend=tail(df$x, n=-1),
yend=tail(df$y, n=-1)),
aes(xend=xend,
yend=yend),
arrow=arrow(length = unit(0.7, "cm"))) +
theme_bw() + theme(legend.position="none") +
xlab("longitude") +
ylab("latitude") +
geom_text(aes(x = jitter(x), y = jitter(y)),
check_overlap = FALSE, size = 7)
g
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句