我最近在"经济学人"中看到了一个折线图,其中标题的颜色与匹配折线图中使用的组的颜色相匹配.我想知道如何使用ggplot2对象执行此操作.下面是一些代码,用于制作包含所有内容的折线图,例如标题中除了彩色字之外的经济学文章.在底部,我显示了所需的输出.
这个问题不是关于显示此信息的理论方法(如直接标记或图例),而是专门用于着色标题中的单个单词.
data <- data.frame(
group = rep(c('affluence', 'poverty'), each = 6),
year = rep(c(1970, 1980, 1990, 2000, 2010, 2012), 2),
concentration = c(.125, .12, .14, .13, .145, .146, .068, .09, .125, .119, .13, .135)
)
library(ggplot2)
ggplot(data, aes(year, concentration, color = group)) +
geom_line(size = 1.5) +
geom_point(size = 4) +
scale_y_continuous(limits = c(0, .15)) +
labs(
x = NULL, y = NULL,
title = 'Concentration of affluence and poverty nationwide'
) +
theme_minimal() +
theme(
legend.position …Run Code Online (Sandbox Code Playgroud) 问候,
我需要在我的图表上显示多色文本
early <- 30
ontime <- 70
late <- 25
txt <- paste(early, ontime, late, sep='/')
plot(1:2, type='n')
text(1.5, 1.5, txt)
Run Code Online (Sandbox Code Playgroud)
我需要早期,正常时间,晚期txt的值,分别为蓝色,绿色和红色.
我在标题中找到了关于多色文本的帖子,但是我无法使其适应我的问题 http://blog.revolutionanalytics.com/2009/01/multicolor-text-in-r.html
谢谢您的帮助