在 ggplot2 中自定义 Social Network Visual 中的线条颜色
Customize color of lines in Social Network Visual in ggplot2
我正在努力解决以下问题。我想象了一个大型社交网络,并想自定义 geom_segment
中捕获的边缘的调色板以获得更好的可见性。例如,我想用红色刻度代替我的蓝色刻度。我怎样才能以最简单的方式实现它?
我有以下运行良好的代码:
ggplot(nodes_geo) + country_shapes +
geom_segment(aes(x = x, y = y, xend = xend, yend = yend, alpha = weight, color = weight # draw edges as arcs
),
data = edges_for_plot, curvature = 0.33,
) +
scale_size_continuous(guide = FALSE, range = c(0.25, 2)) + # scale for edge widths
geom_point(aes(x = longitude, y = latitude, size = weight), # draw nodes
shape = 21, fill = 'white',
color = 'black', stroke = 0.5) +
scale_size_continuous(guide = FALSE, range = c(0.01, 2)) + # scale for node size
mapcoords + maptheme
非常感谢!
感谢 stefan,我使用以下代码使用 scale_color_gradient
将颜色从蓝色更改为红色。
ggplot(nodes_geo) + country_shapes +
geom_curve(aes(x = x, y = y, xend = xend, yend = yend, alpha = weight, color = weight # draw edges as arcs),
data = edges_for_plot, curvature = 0.33,) +
scale_color_gradient(low = "red4", high = "red")+ # <-- Customize color
scale_size_continuous(guide = FALSE, range = c(0.25, 2)) + # scale for edge widths
geom_point(aes(x = longitude, y = latitude, size = weight), # draw nodes
shape = 21, fill = 'white',
color = 'black', stroke = 0.5) +
scale_size_continuous(guide = FALSE, range = c(0.01, 2)) + # scale for node size
mapcoords + maptheme
我正在努力解决以下问题。我想象了一个大型社交网络,并想自定义 geom_segment
中捕获的边缘的调色板以获得更好的可见性。例如,我想用红色刻度代替我的蓝色刻度。我怎样才能以最简单的方式实现它?
我有以下运行良好的代码:
ggplot(nodes_geo) + country_shapes +
geom_segment(aes(x = x, y = y, xend = xend, yend = yend, alpha = weight, color = weight # draw edges as arcs
),
data = edges_for_plot, curvature = 0.33,
) +
scale_size_continuous(guide = FALSE, range = c(0.25, 2)) + # scale for edge widths
geom_point(aes(x = longitude, y = latitude, size = weight), # draw nodes
shape = 21, fill = 'white',
color = 'black', stroke = 0.5) +
scale_size_continuous(guide = FALSE, range = c(0.01, 2)) + # scale for node size
mapcoords + maptheme
非常感谢!
感谢 stefan,我使用以下代码使用 scale_color_gradient
将颜色从蓝色更改为红色。
ggplot(nodes_geo) + country_shapes +
geom_curve(aes(x = x, y = y, xend = xend, yend = yend, alpha = weight, color = weight # draw edges as arcs),
data = edges_for_plot, curvature = 0.33,) +
scale_color_gradient(low = "red4", high = "red")+ # <-- Customize color
scale_size_continuous(guide = FALSE, range = c(0.25, 2)) + # scale for edge widths
geom_point(aes(x = longitude, y = latitude, size = weight), # draw nodes
shape = 21, fill = 'white',
color = 'black', stroke = 0.5) +
scale_size_continuous(guide = FALSE, range = c(0.01, 2)) + # scale for node size
mapcoords + maptheme