在“treemapify”中,我使用函式“paste0”將三個變陣列合為標簽,現在我想分別更改字體顏色和大小(如以下代碼中的注釋)。任何人都可以幫忙嗎?謝謝!
library(ggplot2)
library(treemapify)
library(formattable)
plot_data <- data.frame(
region=c("a","b","c","d","e","f"),
amount=c(3,2,1,7,2,4),
increase=c(0.5,0.1,0.7,0.4,0.3,0.9))
plot_data %>% ggplot(aes(area=amount,fill=region,
label=paste0(region, #' want the font color 'darkblue'
'\n',
comma(amount,1), # want the font color 'grey60'
'\n',
percent(increase,1) # want the font color 'white'
)))
geom_treemap() geom_treemap_text()

uj5u.com熱心網友回復:
這是一個相當普通的解決方案,但它應該為您提供所需的靈活性:
ggplot(plot_data, aes(area = amount, fill = region))
geom_treemap()
geom_treemap_text(aes(label = region), color = "darkblue")
geom_treemap_text(aes(label = scales::comma(amount, 1)),
color = "grey60", padding.y = unit(10, "mm"))
geom_treemap_text(aes(label = scales::percent(increase, 1)), color = "white",
padding.y = unit(20, "mm"))

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/343667.html
上一篇:回圈遍歷動態列
下一篇:將字符向量與資料框匹配并添加新列
