12
Sto creando diversi grafici sfaccettati per un report. Il numero di sfaccettature varia tra 2 e 8. Idealmente, mi piacerebbe che la dimensione assoluta di ogni sfaccettatura (attraverso i grafici) fosse la stessa (ad esempio 4x4 cm) in modo che sia più facile confrontarli (e sembra anche più bella).Impostazione della dimensione assoluta dei facet in ggplot2
È possibile?
df1 <- structure(list(group1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,1L, 1L, 1L, 1L, 1L), .Label = c("S1", "S2"), class = "factor"), group = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("A", "B", "C", "D", "E"), class = "factor"), value = 1:12), class = "data.frame", row.names = c(NA, -12L), .Names = c("group1", "group", "value"))
df2 <- structure(list(group1 = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("S1", "S2"), class = "factor"), group = structure(c(4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L), .Label = c("A", "B", "C", "D", "E"), class = "factor"), value = 13:20), class = "data.frame", row.names = c(NA, -8L), .Names = c("group1", "group", "value"))
library(ggplot2)
plot1 <- ggplot(df1) + geom_histogram(aes(x=value)) + facet_wrap(~group)
plot2 <- ggplot(df2) + geom_histogram(aes(x=value)) + facet_wrap(~group)
Grazie, anche se io ancora non capisco come utilizzare questa funzione senza ricevere un messaggio di errore. Puoi espandere la tua risposta mostrando come ottenere il risultato desiderato con i miei dati di esempio? – beetroot
Ho appena provato questo con R Devel, e questa linea non funziona per me: 'g $ width [panel_index_w] <- rep (list (width), nw)'. Ho bisogno di usare questo: 'g $ width [panel_index_w] <- rep (grid ::: unit.list (width), nw)'. –
Per rispondere al mio commento precedente: la riga 'g $ width [panel_index_w] <- rep (list (width), nw)' dovrebbe essere sostituita da 'g $ width [panel_index_w] <- rep (width, nw)'. Allora le cose funzionano. –