SAS SGPLOT or R ggplot2 - generate separate component for same plot

310 Views Asked by At

enter image description here

I would like to generate a plot as attached using SAS or R. Y-axis has a scale of 1 to 100 as a continuous value (with a break of 21 to 49) and X-axis has a categorical scale with two values.

I need to allocate 70% of the plot area to the bottom component (i.e. where values from 0-20 are plotted) and then 30% of the plot area to the top component (i.e. where values from 50 to 100 are plotted).

Is there any way, I can plot 3 different components i.e. 0-20, break for 21-49 and then 50 to 100

1

There are 1 best solutions below

0
On

You could piece each together using gridExtra. And can tweak the zooming with either coord_cartesian() or the heights specification in grid.arrange()

library(tidyverse)
library(gridExtra)

data <- bind_cols(category = rep(c("Category1", "Category2"), 5),
          value = c(sample(0:20,6), sample(50:100,4)),
          group = c(1,1,2,2,3,3,4,4,5,5))
topgraph <- data %>% 
    ggplot(aes(x = category, y = value, group = group)) +
    geom_line() +
    labs(x = "") +
    theme(axis.text.x = element_blank())+
    coord_cartesian(ylim = c(50,100))


lowergraph <- data %>% 
    ggplot(aes(x = category, y = value, group = group)) +
    geom_line() +
    coord_cartesian(ylim = c(0,20))




grid.arrange(topgraph, lowergraph, heights = c(.3,.7))