点的大小并不总是与图表中其他点的大小相关
The size of points does not always seem relevant with the size of other points in chart
我有以下数据框:
bt<-structure(list(year2 = c(1955, 1960, 1965, 1970, 1975, 1980,
1985, 1990, 1995, 2000, 2005, 2010, 2015), issue = c("health",
"health", "health", "health", "health", "health", "health", "health",
"health", "health", "health", "health", "health"), country = c("EU",
"EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU",
"EU"), pta_count = c(1, 3, 5, 12, 10, 2, 2, 14, 13, 9, 8, 6,
5), value = c(NA, 2, 4, 11, 7, 1, 2, 13, 12, 9, 8, 6, 5), x = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), x2 = c(1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1), percent = c(NA, 0.666666666666667, 0.8,
0.916666666666667, 0.7, 0.5, 1, 0.928571428571429, 0.923076923076923,
1, 1, 1, 1), percvalue = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1)), row.names = c(NA, -13L), class = c("tbl_df", "tbl", "data.frame"
))
并且我试图创建一个点图,其中灰色圆圈始终代表 value
的 100%
这就是为什么它总是 1
并且内部的绿色圆圈应该代表percent
(value/pta_count
)。问题是绿色圆圈似乎与他们的 value.For 示例不相关 50%
与灰色圆圈和 66.67%
相比有一个非常小的绿色圆圈。我不知道是什么问题。也许我应该在 y 轴上使用另一个值。
f <- bt %>%
ggplot(aes(x = year2)) +
geom_point(aes(y = percvalue, size = percvalue, text = paste0("Year: ", year2)),
color = "gray") +
geom_point(aes(y = percvalue, size = percent,
# text = paste0("Year: ", year2, "\nPercent: ", round(percent, 3) * 100, "%")),
text = paste0("Year: ", year2, "\nPercentage of all signed PTAs covering NTIs: ", scales::percent(percent))),
color = "darkolivegreen") +
scale_x_continuous(n.breaks = 14) +
theme_bw()+
theme(legend.position = 'none',
axis.title.y = element_blank(),
axis.text.y = element_blank()) +
labs(x = "")
你可以将比例乘以一个固定的数量(比如 8,尽管你可以使用任何适合你的数字来使你的数据清晰),然后使用 scale_size_identity
。这样可以确保点的大小始终与其值成正比。
ggplot(bt, aes(x = year2, y = percvalue)) +
geom_point(aes(size = 8 * percvalue), color = "gray") +
geom_point(aes(size = 8 * percent), color = "darkolivegreen") +
geom_text(aes(y = percvalue, label = scales::percent(percent, 1)),
nudge_y = 0.25, size = 3) +
scale_x_continuous(n.breaks = 14) +
scale_y_continuous(limits = c(0, 2)) +
scale_size_identity() +
theme_bw() +
theme(legend.position = 'none',
axis.title.y = element_blank(),
axis.text.y = element_blank()) +
labs(x = "")
我有以下数据框:
bt<-structure(list(year2 = c(1955, 1960, 1965, 1970, 1975, 1980,
1985, 1990, 1995, 2000, 2005, 2010, 2015), issue = c("health",
"health", "health", "health", "health", "health", "health", "health",
"health", "health", "health", "health", "health"), country = c("EU",
"EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU",
"EU"), pta_count = c(1, 3, 5, 12, 10, 2, 2, 14, 13, 9, 8, 6,
5), value = c(NA, 2, 4, 11, 7, 1, 2, 13, 12, 9, 8, 6, 5), x = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), x2 = c(1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1), percent = c(NA, 0.666666666666667, 0.8,
0.916666666666667, 0.7, 0.5, 1, 0.928571428571429, 0.923076923076923,
1, 1, 1, 1), percvalue = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1)), row.names = c(NA, -13L), class = c("tbl_df", "tbl", "data.frame"
))
并且我试图创建一个点图,其中灰色圆圈始终代表 value
的 100%
这就是为什么它总是 1
并且内部的绿色圆圈应该代表percent
(value/pta_count
)。问题是绿色圆圈似乎与他们的 value.For 示例不相关 50%
与灰色圆圈和 66.67%
相比有一个非常小的绿色圆圈。我不知道是什么问题。也许我应该在 y 轴上使用另一个值。
f <- bt %>%
ggplot(aes(x = year2)) +
geom_point(aes(y = percvalue, size = percvalue, text = paste0("Year: ", year2)),
color = "gray") +
geom_point(aes(y = percvalue, size = percent,
# text = paste0("Year: ", year2, "\nPercent: ", round(percent, 3) * 100, "%")),
text = paste0("Year: ", year2, "\nPercentage of all signed PTAs covering NTIs: ", scales::percent(percent))),
color = "darkolivegreen") +
scale_x_continuous(n.breaks = 14) +
theme_bw()+
theme(legend.position = 'none',
axis.title.y = element_blank(),
axis.text.y = element_blank()) +
labs(x = "")
你可以将比例乘以一个固定的数量(比如 8,尽管你可以使用任何适合你的数字来使你的数据清晰),然后使用 scale_size_identity
。这样可以确保点的大小始终与其值成正比。
ggplot(bt, aes(x = year2, y = percvalue)) +
geom_point(aes(size = 8 * percvalue), color = "gray") +
geom_point(aes(size = 8 * percent), color = "darkolivegreen") +
geom_text(aes(y = percvalue, label = scales::percent(percent, 1)),
nudge_y = 0.25, size = 3) +
scale_x_continuous(n.breaks = 14) +
scale_y_continuous(limits = c(0, 2)) +
scale_size_identity() +
theme_bw() +
theme(legend.position = 'none',
axis.title.y = element_blank(),
axis.text.y = element_blank()) +
labs(x = "")