#Rstats #ggplot2: Plotting Functions with stat_function, Adding Labels and Legends. Tunning your plot!

For my Master thesis i need to plot functions, and of course, i'm using ggplot2

require(ggplot2)
vpge0 <- function(x) {281* x ^-0.63}
vpge1 <- function(x) {(11.2+(-0.102*x)+.000677*x^2)/(1+0.129*x+(-0.000947*x^2))}
vpge3 <- function(x) {( (0.717+11.4*x)/(1+35.4*x+(-0.248*x^2)) )}
vpge4 <- function(x) {( (1.36*(10^-1)+(-8.91*(10^-4)*x))/(1+(-1.41*(10^-2)*x)+(4.99*(10^-5)*x^2)) )}
ggplot(NULL, aes(x=x, colour = FE)) +
stat_function(data = data.frame(x = 5:100, FE = factor(1)),
fun = vpge1, size=1) +
stat_function(data = data.frame(x = 5:100, FE = factor(2)),
fun = vpge3, size=1) +
stat_function(data = data.frame(x = 5:100, FE = factor(3)),
fun = vpge4, size=1) +
scale_colour_manual(values = c("red", "blue", "green"),
name = "FE Modem 5",
labels = c("VPG Euro 1", "VPG Euro 3", "VPG Euro 4"))+
ggtitle("Factores de emisión CO (g/km)")+
theme(plot.title = element_text(lineheight=.8, face="bold"))+
ylab("(g/km)")+
xlab("Velocidad Promedio (k/hm)")+
theme(legend.position=c(.7, .7))
view raw ggplot2 hosted with ❤ by GitHub


vpge0: Vehículo Pasajeros Gasolineros Pre-Euro
vpge1: Vehículo Pasajeros Gasolineros Euro 1
vpge3: Vehículo Pasajeros Gasolineros Euro 3
vpge4: Vehículo Pasajeros Gasolineros Euro 4

Comentarios

Entradas populares de este blog

ERROR: Grib2 file or date problem, stopping in edition_num. Can't ungrib.exe SOLVED

ARCGIS: Cálculo de pendiente entre puntos en el espacio xyz

WRF open_aux_u : error opening auxinput5_d02_2013-12-31_00:00:00 for reading. 100