stefanedwards / lemon

🍋 Lemon --- Freshing up your ggplots
https://cran.r-project.org/package=lemon
GNU General Public License v3.0
180 stars 12 forks source link

How to drop unused categories in x axis? #32

Open msgoussi opened 7 months ago

msgoussi commented 7 months ago

library(ggplot2) library(lemon) df <- data.frame( v1 = c("A", "A", "A", "B", "B", "B"), v2 = c("S1", "S2", "S3", "S7", "S8", "S9"), nm = c(2, 3, 4, 5, 6, 7) )

ggplot(df, aes(x = v2, y = nm)) + geom_point(size = 3) + facet_rep_grid(v1~., scales = "free_x", repeat.tick.labels = T)

image

stefanedwards commented 7 months ago

facet_grid (and my derivation) are constrained that the x-axis must be the same in each column, even when using scales = 'free_x. Without the latter argument, the x-axis is the same across all columns.

Similarly for y-axis for each row.

You should be looking at the facet_wrap function. In your case here, I am not even sure you need my package.

lør. 25. nov. 2023 10.38 skrev msgoussi @.***>:

library(ggplot2) library(lemon) df <- data.frame( v1 = c("A", "A", "A", "B", "B", "B"), v2 = c("S1", "S2", "S3", "S7", "S8", "S9"), nm = c(2, 3, 4, 5, 6, 7) )

ggplot(df, aes(x = v2, y = nm)) + geom_point(size = 3) + facet_rep_grid(v1~., scales = "free_x", repeat.tick.labels = T)

image.png (view on web) https://github.com/stefanedwards/lemon/assets/18138496/b0ef06db-5c30-4ccb-aeb9-fe8a3eaf3b98

— Reply to this email directly, view it on GitHub https://github.com/stefanedwards/lemon/issues/32, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3NBGSVKK5GJBJAJU2C3PDYGG4CTAVCNFSM6AAAAAA7Z7F37CVHI2DSMVQWIX3LMV43ASLTON2WKOZSGAYTANJUG43DAOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>