0

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

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
R007
  • 101
  • 1
  • 13
  • This looks promising - http://support.sas.com/kb/55/683.html – thelatemail Jul 11 '21 at 23:44
  • Thanks, Yes we can specify multiple ranges but I am looking for allocating 70% area (i.e. zoom 0-20 to use 70% of plot area) and use 30% area for 51-100 (which is a bigger range than 0-20) – R007 Jul 11 '21 at 23:46
  • I don't *think* this is possible directly in SAS. If it is, it's in GTL. You could have a categorical axis like this, but only if you're okay with Y being categorical - it might be possible to do the chart you want using something like HLINE - but a plot where it's important that the vertical (Y) axis is linear, I don't think it is possible. I would consider heading over to communities.sas.com and post there - maybe Dan or Rob have ideas for how to do it, perhaps. – Joe Jul 13 '21 at 16:30

1 Answers1

1

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))
Jonni
  • 804
  • 5
  • 16