Tópicos em Química Atmosférica - Lista 2
Tarea 2 de Tópicos em Química Atmosférica. Hay que calcular las concentraciones de gases a diferentes alturas.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(ggplot2) | |
N2<-78.084 | |
O2<-20.948 | |
CO2<-0.04 | |
CH4<-0.0002 | |
N2o<-N2*(1/100)*10^6 | |
O2o<-O2*(1/100)*10^6 | |
CO2o<-CO2*(1/100)*10^6 | |
CH4o<-CH4*(1/100)*10^6 | |
N2x <- function(x) {N2o*exp(-x/8)} | |
O2x <- function(x) {O2o*exp(-x/8)} | |
CO2x <- function(x) {CO2o*exp(-x/8)} | |
CH4x <- function(x) {CH4o*exp(-x/8)} | |
N2x(0) | |
[1] 780840 | |
N2x(5) | |
[1] 417953.5 | |
N2x(50) | |
[1] 1507.376 | |
N2x(100) | |
[1] 2.90992 | |
N2x(200) | |
[1] 1.084426e-05 | |
#Tudos | |
ggplot(NULL, aes(x=x, colour = CONC)) +coord_flip()+ | |
stat_function(data = data.frame(x = 5:200, CONC = factor(1)), | |
fun = N2x, size=1) + | |
stat_function(data = data.frame(x = 5:200, CONC = factor(2)), | |
fun = O2x, size=1) + | |
stat_function(data = data.frame(x = 5:200, CONC = factor(3)), | |
fun = CO2x, size=1) + | |
stat_function(data = data.frame(x = 5:200, CONC = factor(4)), | |
fun = CH4x, size=1) + | |
scale_colour_manual(values = c("red","green","blue","black"), | |
name = "Concentração Nitrogênio", | |
labels = c("Nitrogênio","Oxigẽnio","Dióxido de Carbono","Metano"))+ | |
ggtitle("Concentracão (ppm) e Altura (km)")+ | |
theme(plot.title = element_text(lineheight=2, face="bold"))+ | |
ylab("Razáo de mistura (ppm)")+ | |
xlab("z (km)")+ | |
theme(legend.position=c(.7, .7)) | |
#No se ve un carajo |
Y ahora graficando con multiplot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Nitrogênio | |
p1<-ggplot(NULL, aes(x=x, colour = CONC)) +coord_flip()+ | |
stat_function(data = data.frame(x = 5:200, CONC = factor(1)), | |
fun = N2x, size=1) + | |
scale_colour_manual(values = c("red"), | |
name = "Concentração Nitrogênio", | |
labels = c("Nitrogênio"))+ | |
ggtitle("Nitrogênio (ppm) e Altura (km)")+ | |
theme(plot.title = element_text(lineheight=2, face="bold"))+ | |
ylab("Razáo de mistura (ppm)")+ | |
xlab("z (km)")+ | |
theme(legend.position=c(.7, .7)) | |
#Oxigẽnio | |
p2<-ggplot(NULL, aes(x=x, colour = CONC)) + coord_flip()+ | |
stat_function(data = data.frame(x = 5:200, CONC = factor(1)), | |
fun = O2x, size=1) + | |
scale_colour_manual(values = c("blue"), | |
name = "Concentração Oxigẽnio", | |
labels = c("Oxigẽnio"))+ | |
ggtitle("Oxigẽnio (ppm) e Altura (km)")+ | |
theme(plot.title = element_text(lineheight=2, face="bold"))+ | |
ylab("Razáo de mistura (ppm)")+ | |
xlab("z (km)")+ | |
theme(legend.position=c(.7, .7)) | |
#Dióxido de Carbono | |
p3<-ggplot(NULL, aes(x=x, colour = CONC)) + coord_flip()+ | |
stat_function(data = data.frame(x = 5:200, CONC = factor(1)), | |
fun = CO2x, size=1) + | |
scale_colour_manual(values = c("green"), | |
name = "Dióxido de Carbono", | |
labels = c("Dióxido de Carbono"))+ | |
ggtitle("Dióxido de Carbono (ppm) e Altura (km)")+ | |
theme(plot.title = element_text(lineheight=2, face="bold"))+ | |
ylab("Razáo de mistura (ppm)")+ | |
xlab("z (km)")+ | |
theme(legend.position=c(.7, .7)) | |
#Metano | |
p4<-ggplot(NULL, aes(x=x, colour = CONC)) + coord_flip()+ | |
stat_function(data = data.frame(x = 5:200, CONC = factor(1)), | |
fun = CH4x, size=1) + | |
scale_colour_manual(values = c("black"), | |
name = "Metano", | |
labels = c("Metano"))+ | |
ggtitle("Metano (ppm) e Altura (km)")+ | |
theme(plot.title = element_text(lineheight=2, face="bold"))+ | |
ylab("Razáo de mistura (ppm)")+ | |
xlab("z (km)")+ | |
theme(legend.position=c(.7, .7)) | |
#multiplot | |
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) { | |
require(grid) | |
plots <- c(list(...), plotlist) | |
numPlots = length(plots) | |
if (is.null(layout)) { | |
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)), | |
ncol = cols, nrow = ceiling(numPlots/cols)) | |
} | |
if (numPlots==1) { | |
print(plots[[1]]) | |
} else { | |
grid.newpage() | |
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout)))) | |
for (i in 1:numPlots) { | |
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE)) | |
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row, | |
layout.pos.col = matchidx$col)) | |
} | |
} | |
} | |
multiplot(p1,p2,p3,p4, cols=2) |

Comentarios
Publicar un comentario