简体   繁体   English

SAS SGPLOT 或 R ggplot2 - 为同一图生成单独的组件

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

在此处输入图像描述

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.我想生成一个使用 SAS 或 R 附加的图。Y 轴的刻度为 1 到 100 作为连续值(中断为 21 到 49),X 轴有一个带有两个值的分类刻度。

I need to allocate 70% of the plot area to the bottom component (ie where values from 0-20 are plotted) and then 30% of the plot area to the top component (ie where values from 50 to 100 are plotted).我需要将 70% 的绘图区域分配给底部组件(即绘制 0-20 的值),然后将 30% 的绘图区域分配给顶部组件(即绘制 50 到 100 的值)。

Is there any way, I can plot 3 different components ie 0-20, break for 21-49 and then 50 to 100有什么办法吗,我可以绘制 3 个不同的分量,即 0-20,中断 21-49,然后 50 到 100

You could piece each together using gridExtra.您可以使用 gridExtra 将它们拼凑在一起。 And can tweak the zooming with either coord_cartesian() or the heights specification in grid.arrange()并且可以使用 coord_cartesian() 或 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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM