【发布时间】:2016-05-27 12:11:25
【问题描述】:
问题与此有关:Line graph customization (add circles, colors),但由于我有一个新任务,所以我创建了一个新问题。
所以我的数据框再次与我在链接中发布的问题相同。使用下面的代码和@beetroot 给我的(我自己的一点修改)
value <- c(9, 4, 10, 7, 10,
10, 10, 4, 10,
4, 10, 2, 5, 5, 4)
names <- c("a","b",
"c","d","e",
"f", "g","h",
"i","j","k","l",
"m","n","p")
df <- data.frame(value, names)
df$names <- as.character(df$names)
df$part <- rep(c("part3", "part2", "part1"), each = 5)
library(dplyr)
library(tidyr)
df2 <- df %>%
group_by(part, names) %>%
expand(value = min(df$value):max(df$value))
p <- ggplot() +
geom_point(data = df2, aes(x = value, y = names),
shape = 1) +
geom_point(data = df, aes(y = names, x = value, group = 1),
colour = I("red"), shape = 21, lwd = 3, fill = "red") +
geom_line(data = df, aes(y = names, x = value, group = 1),
group = I(1),color = I("red")) +
theme_bw() +
facet_wrap(~part, ncol = 1, scales = "free_y")
p + theme(strip.background = element_rect(fill="dodgerblue3"),
strip.text.x = element_text(colour = "white"))+xlab("") +ylab("")
df <- data.frame(value, names)
df$names <- as.character(df$names)
我得到这个输出:
但现在我想通过(PART1、PART2 和 PART3)连接线,这样我的 输出 看起来像:
我使用了黑色的线条,这样我想将这些部分与线条连接起来会更明显。
【问题讨论】:
-
不确定这是否可能与stackoverflow.com/questions/31690007/…的原理相同
-
如果你想像这样连接不同构面的数据,你不应该使用构面。相反,您可以使用矩形和文本来注释您的绘图。