我正在繪制一個合作者網路,其中點大小按一個國家/地區撰寫的文章數量進行縮放,點之間的線代表合作,線寬和不透明度按合作數量縮放。例如
library(tidyverse)
# data for lines
df_links <- structure(list(from = c("Argentina", "Argentina", "Canada",
"Austria", "Austria", "Italy", "Austria",
"Italy", "New Zealand"),
to = c("Canada", "Germany", "Germany", "Italy",
"New Zealand", "New Zealand", "Panama",
"Panama", "Panama"),
collabs = c(1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L),
x = c(-64, -64, -106, 15, 15, 13, 15, 13, 175),
y = c(-38, -38, 56, 48, 48, 42, 48, 42, -41),
x_end = c(-106, 10, 10, 13, 175, 175, -81, -81, -81),
y_end = c(56, 51, 51, 42,-41, -41, 9, 9, 9)),
row.names = c(NA, -9L),
class = c("tbl_df", "tbl", "data.frame"))
# data for points
df_points <- structure(list(name = c("Argentina", "Austria", "Australia",
"Canada", "Germany", "France", "United Kingdom",
"Italy", "New Zealand", "Panama", "Venezuela"),
papers = c(1L, 1L, 1L, 22L, 3L, 2L, 1L, 1L, 2L, 1L, 1L),
x = c(-64, 15, 134, -106, 10, 2, -3, 13, 175, -81, -67),
y = c(-38, 48, -25, 56, 51, 46, 55, 42, -41, 9, 6)),
row.names = c(NA, -11L),
class = c("tbl_df", "tbl", "data.frame"))
#plot
ggplot()
geom_curve(data = df_links,
aes(x = x, y = y,
xend = x_end,
yend = y_end,
size = collabs,
alpha = collabs),
curvature = 0.33)
geom_point(data = df_points,
aes(x = x,
y = y,
size = papers),
colour = "red")
coord_fixed(xlim = c(-150, 180), ylim = c(-55, 80))
theme_void()

我的問題是傳說。我想要:
- 一個名為 collabs 的圖例,它具有線條粗細和線條不透明度
- 一個名為papers的圖例,它是點大小
相反,我在一個圖例中有論文和協作(線條大小和點大小),在一秒鐘內有不透明度。我認為這個問題是因為我使用的尺寸內aes兩個geom_curve和geom_point?
例如我想要這樣的東西(在inkscape中編輯)

任何建議將不勝感激!
uj5u.com熱心網友回復:
這可以通過ggnewscale允許相同美學的多個比例和圖例的包來實作:
library(tidyverse)
library(ggforce)
library(ggnewscale)
ggplot()
geom_curve(data = df_links,
aes(x = x, y = y,
xend = x_end,
yend = y_end,
size = collabs,
alpha = collabs),
curvature = 0.33)
new_scale("size")
geom_point(data = df_points,
aes(x = x,
y = y,
size = papers),
colour = "red")
coord_fixed(xlim = c(-150, 180), ylim = c(-55, 80))
theme_void()

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/315844.html
下一篇:如何從閃亮的點擊中獲得x類別
