Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 强制y轴从0开始,插入";“中断”;,并且使用ggplot2具有较大的y轴_R_Ggplot2_Yaxis - Fatal编程技术网

R 强制y轴从0开始,插入";“中断”;,并且使用ggplot2具有较大的y轴

R 强制y轴从0开始,插入";“中断”;,并且使用ggplot2具有较大的y轴,r,ggplot2,yaxis,R,Ggplot2,Yaxis,长期潜伏者又问了一个问题 我仍在努力最终确定一个可复制的数字以供出版。审阅者希望看到以下绘图的y轴从0开始,并包含换行符“/”。y轴不仅需要相当大(想象一下,1500个单位),还需要非常紧密地放大(想象一下,300个单位)。这使得审阅者希望我们添加一个换行符,以表示轴从0开始,但继续 我可以创建的示例: 我想要的示例(注意y轴;这是在类似图中的powerpoint中手动完成的): 有什么想法吗??谢谢 我的代码: ggplot(data = quad2, aes(x, pred

长期潜伏者又问了一个问题

我仍在努力最终确定一个可复制的数字以供出版。审阅者希望看到以下绘图的y轴从0开始,并包含换行符“/”。y轴不仅需要相当大(想象一下,1500个单位),还需要非常紧密地放大(想象一下,300个单位)。这使得审阅者希望我们添加一个换行符,以表示轴从0开始,但继续

我可以创建的示例:

我想要的示例(注意y轴;这是在类似图中的powerpoint中手动完成的):

有什么想法吗??谢谢

我的代码:

ggplot(data = quad2,
       aes(x, predicted, group = group)) +
  geom_point(aes(shape = group), size = 6) +
  scale_shape_manual(values=c(19, 1)) +
  geom_line(size = 2,
            aes(linetype = group),
            color = "black") +
  scale_linetype_manual(values = c("solid", "dashed")) +
  geom_linerange(size = 1,
                 aes(ymin = predicted - conf.low,
                     ymax = predicted + conf.high),
                 color = "black",
                 alpha = .8) +
   geom_segment(aes(xend = x,
                    yend = ifelse(group == "Control", conf.high, conf.low)),
                arrow = arrow(angle = 90), color = "red")+
    labs(x = "Time",
       y = expression(bold("QUAD Volume (cm"^"3"*")")),
       linetype = "",
       shape = "") + #Legend title
  scale_y_continuous(limits =c(1500, 2000)) 
可复制数据:

dput(quad2)
structure(list(x = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 
5L, 5L), .Label = c("PRE", "MID1", "MID2", "MID3", "POST"), class = "factor"), 
    predicted = c(1666.97185871754, 1660.27445165342, 1743.2831065274, 
    1678.48945165342, 1788.50605542978, 1637.40907049806, 1807.55826371403, 
    1639.78265640012, 1865.8766220711, 1652.91070173056), std.error = c(88.8033117577884, 
    91.257045996107, 92.9973963841595, 95.3834973421298, 95.0283457128716, 
    97.3739053806999, 95.6466346849776, 97.9142418717957, 93.3512943191676, 
    95.5735155125126), conf.low = c(0, 91.257045996107, 0, 95.3834973421298, 
    0, 97.3739053806999, 0, 97.9142418717957, 0, 95.5735155125126
    ), conf.high = c(88.8033117577884, 0, 92.9973963841595, 0, 
    95.0283457128716, 0, 95.6466346849776, 0, 93.3512943191676, 
    0), group = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
    2L), .Label = c("Intervention", "Control"), class = "factor")), class = "data.frame", row.names = c(NA, 
-10L))

据我所知,ggplot2不支持轴打断。据我所知,
facet\u grid

有一个解决方案ggplot2不支持轴打断。有一种解决方案是使用
facet\u grid

绘制不连续轴,这是因为您应该尽可能避免这样做。虽然我不同意你的评论者的观点,但如果你真的想要y轴断裂的话,你可以对底层的网格图形不屑一顾

首先制定你的计划。我只添加了y轴格式和轴线主题。我们将只在底部打上“0”的标签


plt绘制不连续轴之所以困难,是因为您应该尽可能避免这样做。虽然我不同意你的评论者的观点,但如果你真的想要y轴断裂的话,你可以对底层的网格图形不屑一顾

首先制定你的计划。我只添加了y轴格式和轴线主题。我们将只在底部打上“0”的标签


plt通常,如果要比较效果的大小,显示轴的原点确实有意义。但一个不连续的轴心国也不符合这一点。我要做的是对数据进行日志转换。如果您使用非连续轴,您将故意选择建议比可能存在的效果尺寸更大的效果尺寸。(特别是因为这是一个立方尺度的差异)。我的两分钱:)我认为@teunbrand显示了一个很好的解决方案通常,如果你想比较效果的大小,显示轴的原点确实是有意义的。但一个不连续的轴心国也不符合这一点。我要做的是对数据进行日志转换。如果您使用非连续轴,您将故意选择建议比可能存在的效果尺寸更大的效果尺寸。(特别是因为这是一个立方尺度的差异)。我的两分钱价值:)我认为@teunbrand表现出了巨大的潜力solution@teunbrand你能解释一下你到底在用这个做什么吗<代码>yline$x我正在更改轴线的基础数据。
单位(…,“npc)
位于标准化的父坐标中,这意味着相对于它放置在[0-1]中的单元格。id
告诉这条线,第一和第二个坐标属于一条线,第三和第二条线。箭头是为了使这条线的末端看起来像
-|
@teunbrand你能解释一下你到底在用它做什么吗?
yline$x我正在更改轴线的基础数据de>单位(…,“npc)
在标准化的父坐标中,这意味着相对于它放置在[0-1]中的单元格。
id
告诉该行,第一个和第二个坐标属于一行,第三个和第二个坐标属于第二行。箭头使线条的末端看起来像
-|
plt <- ggplot(data = quad2,
       aes(x, predicted, group = group)) +
  geom_point(aes(shape = group), size = 6) +
  scale_shape_manual(values=c(19, 1)) +
  geom_line(size = 2,
            aes(linetype = group),
            color = "black") +
  scale_linetype_manual(values = c("solid", "dashed")) +
  geom_linerange(size = 1,
                 aes(ymin = predicted - conf.low,
                     ymax = predicted + conf.high),
                 color = "black",
                 alpha = .8) +
  geom_segment(aes(xend = x,
                   yend = ifelse(group == "Control", conf.high, conf.low)),
               arrow = arrow(angle = 90), color = "red")+
  labs(x = "Time",
       y = expression(bold("QUAD Volume (cm"^"3"*")")),
       linetype = "",
       shape = "") + #Legend title
  scale_y_continuous(limits =c(1400, 2000),
                     breaks = seq(1400, 2000, by = 200),
                     labels = c(0, seq(1600, 2000, by = 200)),
                     expand = c(0,0,0.05,0)) +
  theme(axis.line = element_line())
gt <- ggplotGrob(plt)

is_yaxis <- which(gt$layout$name == "axis-l")
yaxis <- gt$grobs[[is_yaxis]]

# You should grab the polyline child
yline <- yaxis$children[[1]]
yline$x <- unit(rep(1, 4), "npc")
yline$y <- unit(c(0, 0.1, 1, 0.15), "npc")
yline$id <- c(1, 1, 2, 2)
yline$arrow <- arrow(angle = 90)
yaxis$children[[1]] <- yline

gt$grobs[[is_yaxis]] <- yaxis

# grid plotting syntax
grid.newpage(); grid.draw(gt)