我正在创建一个关联的圆形图,我想绘制两种类型的信息:
用于绘制每个箭头/点的颜色集成在data.all all
:
(更新)我的代码是:
## Colors for datasets
fColor <- c("yellow", "blue", "green", "red")
names(fColor) <- c("background", "isolation_p", "media", "solution")
## /
## Filters for 0s
f1 <- all[ , 1] != 0 & all[ , 2] != 0
f2 <- all[ , 1] == 0 | all[ , 2] == 0
## /
## Draw Circle
theta <- c(seq(-pi, pi, length = 50), seq(pi, -pi, length = 50))
circle <- data.frame(xcircle = cos(theta), ycircle = sin(theta))
p <- ggplot2::ggplot(data = circle, ggplot2::aes_string("xcircle", "ycircle")) +
ggplot2::geom_path(ggplot2::aes_string("xcircle", "ycircle")) +
ggplot2::geom_hline(yintercept = 0, linetype = "dashed") +
ggplot2::geom_vline(xintercept = 0, linetype = "dashed")
## /
## Draw arrows
p <- p + ggplot2::geom_segment(data = all[f1, ],
ggplot2::aes_string(x = 0, y = 0, xend = "x", yend = "y"),
arrow = grid::arrow(length = grid::unit(0.2, "cm")),
color = fColor[all$feature[f1]], linetype = "solid")
## /
## Draw points
p <- p + ggplot2::geom_point(data = all[f2, ],
ggplot2::aes_string("x", "y"),
color = fColor[all$feature[f2]], shape = 19, size = 2)
## /
## Add axis labels
p <- p + ggplot2::scale_y_continuous("First Component") +
ggplot2::scale_x_continuous("Second Component")
## /
现在我想为图中使用的颜色添加图例,但我无法添加它。 ¿有些想法?
(更新)我想在传奇中看到的是解决方案的红色子弹,媒体的绿色子弹,背景的黄色子弹和背景的蓝色子弹(使用来自功能的标签,all
的第3列)。
(更新)我all
data.frame的片段:
all <- read.table(text = "x y feature
yc01002711 -0.1755657 0.0000000000 background
yc02001111 0.0000000 -0.0006935916 background
yc03001287 0.0000000 -0.3966829792 background
yc04001667 0.0000000 -0.0575593341 background
xx00000091 -0.4205095 0.0000000000 isolation_p
xx00000092 0.0000000 -0.0085758016 isolation_p
sc78 0.03099176 -0.1425365 media
sc88 0.03897109 0.0000000 media
sc09 -0.05278946 0.0000000 media
inm10058 -0.05277376 0.0000000 solution
inm10099 -0.05286904 0.0000000 solution
inm10101 -0.08174610 -0.1315094 solution")
绘制情节的示例:
答案 0 :(得分:0)
当我运行你的代码时,我没有得到你所展示的完全相同的数字,但是如果你运行这段代码,我得到的是我运行你的代码时得到的相同数字但你想要的传奇。
而不是在绘图之前使用aes_string()I子集。
f2_s <- all[f2, ]
p <- p + geom_point(data = f2_s, aes(x, y, color=feature), shape = 19, size = 2)
p
p + scale_color_manual(values=c("yellow", "blue", "green", "red"))
p + scale_color_manual(values=c("yellow", "blue", "green", "red")) + scale_y_continuous("First Component") + scale_x_continuous("Second Component")