【发布时间】:2015-11-02 20:45:26
【问题描述】:
当我使用ggplot2 制作地图并尝试使用expression() 和italic() 的组合使用字符串将图形标题的一部分斜体化时,我的地图会根据需要显示:
plottitle <- expression(paste('Example map with ', italic('italics')))
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
states_map <- map_data("state")
map <- ggplot(crimes, aes(map_id = state)) +
geom_map(aes(fill = Murder),
map = states_map) +
expand_limits(x = states_map$long,
y = states_map$lat) +
labs(title = plottitle)
map
但是,当我尝试做同样的事情,但使用对象而不是字符串时,对象不会评估为所需的字符串:
word <- 'italics'
plottitle2 <- expression(paste('Example map with ', italic(word)))
map <- ggplot(crimes, aes(map_id = state)) +
geom_map(aes(fill = Murder),
map = states_map) +
expand_limits(x = states_map$long,
y = states_map$lat) +
labs(title = plottitle2)
map
在应用italic() 之前,如何获取向量word 进行评估?
【问题讨论】: