Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.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 在ggplot中将打印窗口扩展到x轴标签之外_R_Ggplot2 - Fatal编程技术网

R 在ggplot中将打印窗口扩展到x轴标签之外

R 在ggplot中将打印窗口扩展到x轴标签之外,r,ggplot2,R,Ggplot2,在ggplot中,我有一个图形,其x轴标签延伸到RStudio中的绘图窗口之外,即使我尝试导出图片,也不管图片有多宽。下面是我当前使用连续缩放中的限制的解决方案。是否可以扩展图片,以便在不扩展线段的情况下捕获最后一个x轴标签(即25021643) 要复制上述内容的代码: library(ggplot2) p <- ggplot(NULL) + xlab("x-axis") + theme_bw() + scale_x_continuous(breaks = as.i

ggplot
中,我有一个图形,其x轴标签延伸到RStudio中的绘图窗口之外,即使我尝试导出图片,也不管图片有多宽。下面是我当前使用
连续缩放
中的
限制
的解决方案。是否可以扩展图片,以便在不扩展线段的情况下捕获最后一个x轴标签(即25021643)

要复制上述内容的代码:

library(ggplot2)
p <- 
  ggplot(NULL) + 
  xlab("x-axis") + 
  theme_bw() +
  scale_x_continuous(breaks = as.integer(seq(0,25021643,(25021643/4))), limits=c(0,26021643),labels = as.integer(seq(0,25021643,(25021643/4))), expand = c(0,0)) +
  scale_y_continuous(limits = c(-1, (nrow(chr5)+1)), expand = c(0,0))  +
  geom_hline(yintercept = -1) +
  geom_segment(aes(x = 0, y = -1, xend = 0, yend = -0.9)) +
  geom_segment(aes(x = 25021643, y = -1, xend = 25021643, yend = -0.9)) +
  theme(panel.grid.major=element_blank(),
        panel.grid.minor=element_blank(),
        panel.border=element_blank(),
        axis.ticks.y = element_blank(), 
        axis.title.y = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.x = element_line(size=1), 
        axis.title.x = element_text(size=20),
        axis.text.x = element_text(size=20))
p
库(ggplot2)

p添加
plot.margin=unit(c(0,20,0,0),“mm”)
似乎可以完成这项工作。

您还可以使用:

plot.margin=margin(r=20,unit=“mm”)

这只是做同样事情的另一种方式,但要避免为绘图的所有边写值:“t”是顶部,“r”是右侧,“l”是左侧,“b”是底部。您可以用逗号分隔所有或任何边:

plot.margin=margin(r=20,l=30,b=15,t=40,unit=“mm”)

或者,如果您希望使用标准单位(“pt”):


plot.margin=margin(r=20)

一种非常不合理的方法是,仅将x轴终止于先前的值,然后使用
geom_text包含25021643
请包含代码的可复制示例。如果没有可复制示例,则很难添加一个中断…scale_x_continuous(中断=c(062554101251082118766232 25021643)对此很抱歉。我已经添加了代码,它已经在使用中断。