我正在创建一个图形,在得分的主要y轴(缩放比例为0-5)和次要y轴PCR结果(缩放比例为0-45)上显示两个折线图。但是,我需要反转第二个y轴,以使45位于y轴的底部(45 =阴性PCR结果)。我可以绘制次要y轴,但不知道如何反转它。
链接到一些虚拟数据
https://www.filehosting.org/file/details/813109/redditexample.csv
library(data.table)
library(ggplot2)
library(lubridate)
#Read the file you want to use for a graph
data <- fread("redditexample.csv", na.strings = c("", NA))
data$V1 <- lubridate::dmy(data$V1)
plot <- ggplot(data) +
geom_line(aes(x = V1, y = AveScore, col = type)) +
geom_point(aes(x = V1, y = PCR)) +
scale_y_continuous('PCR', sec.axis = sec_axis(trans = "reverse")
也尝试过:
scale_y_continuous('PCR', sec.axis = sec_axis(~ . *-1 + 50))