我想一起使用一个变量(此处为向量元素“类型”)和一个在 n 轴标签内包含上标(此处为 m^2)的单位。
data <- list(houses = data.frame(surface = c(450, 320, 280),
price = c(12, 14, 6)),
flats = data.frame(surface = c(45, 89, 63),
price = c(4, 6, 9)))
我实现使用表达式显示“m^2”,
for (type in c('houses', 'flats')){
p <- ggplot(aes(x = surface, y = price), data = data[[type]]) +
geom_point() +
xlab(expression(paste('surface of this type /', m^{2})))
}
p
但是当我尝试在标签中添加变量时,以下内容当然不起作用:
for (type in c('houses', 'flats')){
p <- ggplot(aes(x = surface, y = price), data = data[[type]]) +
geom_point() +
xlab(expression(paste('surface of ', type, '/', m^{2})))
}
p
您有什么建议吗?