我正在使用ggplot2绘制双轴图。我正在使用下面发布的代码。我试图将其保存到JPEG,但它只保存最后的输出行,而不是两行的绘图,即使轴是正确的。如何同时保存两个相对线的两个轴?我正在尝试ggsave,但它抱怨它不是ggplot2格式。
## Putting plots together ##################
# extract gtable
g1 <- ggplot_gtable(ggplot_build(p1))
g2 <- ggplot_gtable(ggplot_build(p2))
# overlap the panel of 2nd plot on t
我正在创建一个图形,它在分数的主要y轴(缩放比例为0-5)和次要y轴PCR结果(缩放比例为0-45)上显示两个线状图。然而,我需要反转第二个y轴,这样45就在y轴的底部(45 =阴性PCR结果)。我可以绘制第二个y轴,但不知道如何反转它。
链接到一些虚拟数据
library(data.table)
library(ggplot2)
library(lubridate)
#Read the file you want to use for a graph
data <- fread("redditexample.csv", na.strings = c("
有没有人知道怎么用这个?
set.seed(101)
x <- 1:10
y <- rnorm(10)
## second data set on a very different scale
z <- runif(10, min=1000, max=10000)
par(mar = c(5, 4, 4, 4) + 0.3) # Leave space for z axis
plot(x, y) # first plot
par(new = TRUE)
plot(x, z, type = "l", axes = FALSE, bty = "n
似乎总是有一些小的,但明显的偏移,在哪里,滴答标志结束和面板开始。
当指定轴限值时,这一点就更明显了,这样轴就会以一个滴答结束(见上文)。在y轴上,最高的刻度过高,最低的刻度太低。
复制代码:
library(ggplot2) p <- ggplot(mtcars,aes(mpg, wt)) + geom_point() + scale_y_continuous(limits=c(1,5),expand=c(0,0)) p <- p + theme_few() p <- p + theme(axis.ticks=element_line(size=0.5),axis