gpt4 book ai didi

r - 将€符号添加到气泡图中的数据标签 - ggplot?

转载 作者:行者123 更新时间:2023-12-02 15:56:14 24 4
gpt4 key购买 nike

这是我的数据头:

structure(list(asutus = c("Eesti Draamateater", "Eesti Draamateater", 
"Eesti Noorsooteater", "Eesti Noorsooteater", "Rahvusooper Estonia",
"Rahvusooper Estonia", "Rakvere Teatrimaja", "Rakvere Teatrimaja",
"Sakala Teatrimaja", "Vene Teater", "Vene Teater"), liik = c("Kinnisvara haldus ja korraldus",
"Teatrite tugiteenused", "Kinnisvara haldus ja korraldus", "Teatrite tugiteenused",
"Kinnisvara haldus ja korraldus", "Teatrite tugiteenused", "Kinnisvara haldus ja korraldus",
"Teatrite tugiteenused", "Kinnisvara haldus ja korraldus", "Kinnisvara haldus ja korraldus",
"Teatrite tugiteenused"), tooandja_kulu_aastas = c(131980, 455701,
103401, 257137, 124755, 1081211, 49147, 188658, 24373, 105234,
236232)), row.names = c(NA, -11L), class = c("tbl_df", "tbl",
"data.frame"))

我的颜色:

prx_col_palette <- function(){
c("#E69F00",
"#56B4E9",
"#009E73",
"#F0E442",
"#0072B2",
"#D55E00",
"#CC79A7")
}
prx_cols <- prx_col_palette()

我的气泡图:

ggplot(palgad_joonisele2,
aes(x = liik,
y = asutus,
colour = liik,
size = tooandja_kulu_aastas)) +
geom_point() +
geom_text(aes(label = tooandja_kulu_aastas),
colour = "white",
size = 3.5) +
scale_x_discrete(position = "top")+
scale_y_discrete(limits = rev)+
scale_size_continuous(range = c(14, 37)) +
scale_colour_manual(values = prx_cols)+
labs(x = NULL, y = NULL) +
theme(legend.position = "none",
panel.background = element_blank(),
panel.grid = element_blank(),
axis.text.x = element_text(size=11),
axis.text.y = element_text(size=11),
axis.ticks = element_blank())

这就是我的情节现在的样子:

enter image description here

我的问题是 - 如何在图表上的数字之前获取欧元符号 (€) 并格式化数据标签,以便它们更具可读性,因为它们是人工成本。例如:€10 000 不是 10000 或类似 €10,000?

最佳答案

使用包 scales 更改 geom_text 标签。唯一的变化是

label = dollar(tooandja_kulu_aastas, prefix = "\u20ac")

其余代码与问题中的完全相同。

library(ggplot2)
library(scales)

prx_col_palette <- function(){
c("#E69F00",
"#56B4E9",
"#009E73",
"#F0E442",
"#0072B2",
"#D55E00",
"#CC79A7")
}
prx_cols <- prx_col_palette()

ggplot(palgad_joonisele2,
aes(x = liik,
y = asutus,
colour = liik,
size = tooandja_kulu_aastas)) +
geom_point() +
geom_text(aes(label = dollar(tooandja_kulu_aastas, prefix = "\u20ac")),
colour = "white",
size = 3.5) +
scale_x_discrete(position = "top")+
scale_y_discrete(limits = rev)+
scale_size_continuous(range = c(14, 37)) +
scale_colour_manual(values = prx_cols)+
labs(x = NULL, y = NULL) +
theme(legend.position = "none",
panel.background = element_blank(),
panel.grid = element_blank(),
axis.text.x = element_text(size=11),
axis.text.y = element_text(size=11),
axis.ticks = element_blank())

reprex package 创建于 2022-03-14 (v2.0.1)

关于r - 将€符号添加到气泡图中的数据标签 - ggplot?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71472916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com