2

(The images are too be because of my 3k screen, sorry about that)

I've made a plot like below:

enter image description here

For some reasons, I need my ticks on y-axis to start from 0, but omit all ticks in the range from 0 to 40 in the upper one, and start from 0, omit all ticks in the range from 0 to 0.5 in the lower one

For example:

enter image description here

I don't know how to tweak my code in ggplot2, can anyone help?

Here is my code if needed:

ggthemr('fresh', layout = 'scientific',
    spacing = 1, type = 'inner', line_weight = 0.6,
    )

ggplot(tmb, aes(invasion, mean, color = sediment, linetype = nitrogen)) +
    geom_ribbon(
        aes(ymin = mean - standard.error, ymax = mean + standard.error, `group = pair),`
    alpha = 0.3,
    color = NA,
    fill = "gray"
    ) +
geom_line(size = 1) +
geom_point(show.legend = TRUE) +

facet_wrap(~type, scales = "free_y", ncol = 1, strip.position = "left") + 

scale_x_discrete(breaks = NULL, expand = c(0, 0.10)) +
scale_color_discrete("Sediment",
    labels = c("No", "Yes")
    ) +
scale_linetype_discrete("Nitrogen",
    labels = c("No", "Yes")
    ) +

theme(legend.position = "bottom",
    legend.title = element_text(size = 14),
    legend.key.size = unit(2.5, "lines"),
    legend.text = element_text(size = 14),
    panel.spacing.x = unit(0.5, "lines"),
    panel.spacing.y = unit(0.5, "lines"),
    axis.text = element_text(size = 14),
    strip.text.x = element_text(size = 10),
    strip.text.y = element_text(size = 18, margin = margin(0, 0, 0, 5)),
    strip.placement = "outside",
    axis.title.y = element_text(size = 18),
    axis.title.x = element_text(size = 18),
    aspect.ratio = 1 / 1) +

xlab("From not invaded to invaded") +
ylab(NULL)

Many thanks.

  • in don't think there is an "easy" way to do this in ggplot2 - it may be to stop people being misleading. you can search for "truncating ggplot2 axis" for other potential solutions. – zacdav Sep 29 '17 at 05:35
  • Can you please provide a link? I'm not sure what to do after some clueless searches –  Sep 29 '17 at 05:55
  • 1
    https://stackoverflow.com/a/46410176/3330437 – Brian Sep 29 '17 at 06:01
  • Thanks! But it seems impossible to modify each facet individually, it could be a tough task if there are too many facets –  Sep 29 '17 at 07:45
  • Yes, which is why it's not recommended. If something is hard in `ggplot2`, there's usually a thoughtful reason for it. – Brian Sep 29 '17 at 21:32

0 Answers0