[英]how to add text for the dots in ggplot graph R
我正在嘗試為圖表中的點添加數字。 謝謝您的幫助!
percentage.no.work <- cleanData %>% group_by(AREA) %>%
summarise(percentage = mean(ESTIMATED.CITY.UNEMPLOYMENT))
ggplot() +
geom_point(data=percentage.no.work, aes(x=AREA, y=percentage), alpha=0.6, color="purple", size=2) +
geom_smooth(method = "lm") +
theme_minimal() + ggtitle("Percentage Estimated City Unemployment") +
ylab("Percentage")
使用一些虛構的數據,您可以添加這樣的文本標簽。 請注意,您還需要ggplot
中的aes()
而不是geom_point
和group = 1
,以便渲染geom_smooth
。
library(tidyverse)
tribble(
~AREA, ~percentage,
"a", 0.2,
"b", 0.4
) |>
ggplot(aes(AREA, percentage, group = 1), alpha = 0.6, color = "purple", size = 2) +
geom_point() +
geom_text(aes(label = percentage), nudge_x = 0.1) +
geom_smooth(method = "lm") +
theme_minimal() +
ggtitle("Percentage Estimated City Unemployment") +
ylab("Percentage")
由reprex 包(v2.0.1)於 2022-06-04 創建
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.