stefanedwards / lemon

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

Controlling Ticks Repetition. #27

Open g-pacheco opened 2 years ago

g-pacheco commented 2 years ago

Hello,

Thanks a lot for the great package. I understand that one can control the label repetition by using repeat.tick.labels. Would it be possible to add a similar option for the ticks themselves?

Best regards, George.

stefanedwards commented 2 years ago

It is not clear to me, what you mean the similar option for ticks actually should do.

/Stefan

ons. 24. nov. 2021 15.15 skrev George Pacheco @.***>:

Hello,

Thanks a lot for the great package. I understand that one can control the label repetition by using repeat.tick.labels. Would it be possible to add a similar option for the ticks themselves?

Best regards, George.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stefanedwards/lemon/issues/27, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3NBGVNDEJMMFU2MMKK43LUNTXRFANCNFSM5IWFY7HQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

g-pacheco commented 2 years ago

Hello @stefanedwards,

Thanks for your quick reply. Say I have the plot below created with this code:

# Creates Manhattan panel ~
Fst_Window <-
  ggplot() +
  geom_line(data = fulldfa, aes(x = gPoint, y = Fst, colour = Pops), linetype = 1, size = .6) +
  facet_rep_grid(CHR ~. , scales = "free", repeat.tick.labels = "left", labeller = labeller(CHR = y_strip_labels)) +
  scale_x_continuous("Genomic Position",
                     breaks = c(5000000, 10000000, 15000000, 20000000, 25000000, 30000000), 
                     labels = c("5Mb", "10Mb", "15Mb", "20Mb", "25Mb", "30Mb"),
                     limits = c(0, 32000000),
                     expand = c(0, 0)) +
  scale_y_continuous("Fst Across Chrmosomes",
                     breaks = c(.1, .3, .5), 
                     labels = c("0.1", "0.3", "0.5"),
                     limits = c(0, .525),
                     expand = c(0, 0)) +
  scale_colour_manual(values = c("#4daf4a", "#9970ab", "#f46d43")) +
  theme(panel.background = element_rect(fill = "#ffffff"),
        panel.border = element_blank(),
        panel.grid.minor = element_blank(),
        axis.line = element_line(colour = "#000000", size = .3),
        axis.title.x = element_text(size = 20, face = "bold", color = "#000000", margin = margin(t = 30, r = 0, b = 0, l = 0)),
        axis.title.y = element_text(size = 20, face = "bold", color = "#000000", margin = margin(t = 0, r = 30, b = 0, l = 0)),
        axis.text = element_text(colour = "#000000", size = 15),
        axis.ticks = element_line(color = "#000000", size = .3),
        strip.background.y = element_rect(colour = "#000000", fill = "#d6d6d6", size = .3),
        strip.text = element_text(colour = "#000000", size = 11.5, face = "bold"),
        legend.position = "top",
        legend.margin = margin(t = 0, b = 0, r = 0, l = 0),
        legend.box.margin = margin(t = 30, b = 25, r = 0, l = 0),
        legend.key = element_rect(fill = NA),
        legend.background =element_blank()) +
  guides(colour = "none", fill = "none")

I would like to have the ticks on the x-axis just once (very first x-axis down), and not on the repeated x-axis lines. So, the option would allow the user to control this behaviour. What do you think?

Thanks again, George.

BSG_EuropeanFlounder--Fst-Windows-NoStepping_Lines_BalticSea

stefanedwards commented 2 years ago

It seems to me that what you are asking for here is the default behaviour of ggplot2's own facet_grid. Or are you looking to have the x-axis (with ticks and labels) at the bottom of the top-most panel? That would be most unorthodox, and outside the scope of what I can do in a reasonable way. You could consider putting the x-axis (with ticks and labels) at the top, with scale_x_continuous("Genomic Position", position = "top", ....

Den tor. 25. nov. 2021 kl. 09.44 skrev George Pacheco < @.***>:

Hello @stefanedwards https://github.com/stefanedwards,

Thanks for your quick reply. Say I have the plot below created with this code:

Creates Manhattan panel ~

Fst_Window <- ggplot() + geom_line(data = fulldfa, aes(x = gPoint, y = Fst, colour = Pops), linetype = 1, size = .6) + facet_rep_grid(CHR ~. , scales = "free", repeat.tick.labels = "left", labeller = labeller(CHR = y_strip_labels)) + scale_x_continuous("Genomic Position", breaks = c(5000000, 10000000, 15000000, 20000000, 25000000, 30000000), labels = c("5Mb", "10Mb", "15Mb", "20Mb", "25Mb", "30Mb"), limits = c(0, 32000000), expand = c(0, 0)) + scale_y_continuous("Fst Across Chrmosomes", breaks = c(.1, .3, .5), labels = c("0.1", "0.3", "0.5"), limits = c(0, .525), expand = c(0, 0)) + scale_colour_manual(values = c("#4daf4a", "#9970ab", "#f46d43")) + theme(panel.background = element_rect(fill = "#ffffff"), panel.border = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "#000000", size = .3), axis.title.x = element_text(size = 20, face = "bold", color = "#000000", margin = margin(t = 30, r = 0, b = 0, l = 0)), axis.title.y = element_text(size = 20, face = "bold", color = "#000000", margin = margin(t = 0, r = 30, b = 0, l = 0)), axis.text = element_text(colour = "#000000", size = 15), axis.ticks = element_line(color = "#000000", size = .3), strip.background.y = element_rect(colour = "#000000", fill = "#d6d6d6", size = .3), strip.text = element_text(colour = "#000000", size = 11.5, face = "bold"), legend.position = "top", legend.margin = margin(t = 0, b = 0, r = 0, l = 0), legend.box.margin = margin(t = 30, b = 25, r = 0, l = 0), legend.key = element_rect(fill = NA), legend.background =element_blank()) + guides(colour = "none", fill = "none")

I would like to have the ticks on the x-axis just once (very first x-axis down), and not on the repeated x-axis lines. So, the option would allow the user to control this behaviour. What do you think?

Thanks again, George.

BSG_EuropeanFlounder--Fst-Windows-NoStepping_Lines_BalticSea.pdf https://github.com/stefanedwards/lemon/files/7601438/BSG_EuropeanFlounder--Fst-Windows-NoStepping_Lines_BalticSea.pdf

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stefanedwards/lemon/issues/27#issuecomment-978959819, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3NBGSUXW3E72WRIDWXSJTUNXZODANCNFSM5IWFY7HQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

g-pacheco commented 2 years ago

Hej. Sorry for not making myself clear -- thanks for your explanation. I still do not think that what I am looking for is the default behaviour of facet_grid. I was only brave to draw on 3 of them, but I hope you will get the idea. What I would like it to do is to repeat only the x-axis line, and not the x-axis line AND the x-axis ticks. So, the x-axis ticks and labels would appear only once (on the bottom panel ), while the x-axis line would be present in all panels. Does it make more sense now?

InkedBSG_EuropeanFlounder--Fst-Windows-NoStepping_Lines_BalticSea_LI