【发布时间】:2021-08-10 11:35:48
【问题描述】:
我正在尝试使用此 excel Data here 像此 制作一个图形,但我无法将两个具有不同值的变量放在 x 轴上。
library(xlsx2)
test <- read.xlsx2("E:/Plot/oz.xlsx",1, header=TRUE)
test$Ozone = as.numeric(as.character(test$Ozone))
test$Altitude = as.numeric(as.character(test$Altitude))
test$Pressure = as.numeric(as.character(test$Pressure))
round(test$Altitude) # i want to round the values of Altitude
library(ggplot2)
ylim.prim <- c(0, 34) # in this example, precipitation
ylim.sec <- c(1010, 10)
b <- diff(ylim.prim)/diff(ylim.sec)
a <- ylim.prim[1] - b*ylim.sec[1]
ggplot(test, aes(x = Ozone, y = Altitude,color = 'Ozone Partial Pressure (mPa)'))+
geom_path(aes(x = Ozone))+ scale_y_continuous(name="Altitude (km)",sec.axis=sec_axis(~(.- a)/b, name = 'Pressure (hPa)'))+
scale_x_continuous(name="Temperature (km)",sec.axis=sec_axis(~(.), name = 'Temperature (C)'))+
theme_test() + theme(legend.position = c(0.01, 0.14),legend.justification = c(0, -4))
在此阶段我将不胜感激。谢谢
【问题讨论】:
-
看起来像 stackoverflow.com/questions/68722954/… 的副本,但还没有答案。
-
同一用户有两个帐户。我迫切地想找到答案 :) 它的紧迫性
-
这只是关于 x 轴上的标签还是你想在这个图上画第二条线?如果是后者,那么第二行的 x,y 变量应该是什么?
-
只是轴名称的值:请看示例图...x轴应该有温度和臭氧...y轴将保持不变
-
这个问题是在 2 年前提出的,但在 stackoverflow.com/questions/51833159/… 没有答案
标签: r excel ggplot2 plot profile