5
Vorrei utilizzare insieme una variabile (qui l'elemento vettore "tipo") e un'unità contenente un apice (qui m^2) all'interno dell'etichetta dell'asse n.Come utilizzare contemporaneamente apice e variabile in un'etichetta dell'asse con ggplot2
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)))
raggiungo per visualizzare "m^2" utilizzando un'espressione,
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
ma quando provo ad aggiungere la variabile nell'etichetta, quanto segue, naturalmente, non funziona:
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
Avete un suggerimento?