top of page
Foto del escritorCarlos Carlos-Barbacil

Surface plots in R

First, we load the packages "lattice" and "latticeExtra" and our data. You can easily access and download the data of this example following this link:

You can take a quick look of the data using the function "head()". Here we have 15 observations and 3 variables: fish total length (mm), critical swimming speed (cm/s) and water temperature (ºC).

library(lattice)
library(latticeExtra)
Rut <- read.csv("Rutilus.csv", sep = ";")
head(Rut)

Now, we can start plotting our data!

levelplot(log10(Ucrit_cm.s) ~ log10(TL_mm) * Temperature_oC, 
          Rut, panel = panel.levelplot.points) + 
  layer_(panel.2dsmoother(..., n = 200))

Now, it is time to start editing the plot details: the axis labels, the legend, the dot size, the margins and the colors.


levelplot(log10(Ucrit_cm.s) ~ log10(TL_mm) * Temperature_oC, Rut, 
          panel = panel.levelplot.points, 
          cex = 2, #Change dot size
          col.regions = heat.colors(200), #Change the color
          xlab=expression("log"[10]*" (Total length [mm])"),
          ylab = "Temperature (ºC)", #Axis labels
          main =list(label=bquote(italic("Rutilus rutilus")), cex=1.5),
         legend=list(top=list(fun=grid::textGrob(expression(paste("log"[10]*" (",italic("U"),""[crit]*" [cm/s])")), y=0, x=1.09))),
          #Legend label
          xlim = c(log10(min(Rut$TL_mm)),log10(max(Rut$TL_mm))),
          ylim = c(min(Rut$Temperature_oC),max(Rut$Temperature_oC)),
          #Remove white margins
          scales = list(tck = c(1,0))) + #Remove some ticks
  layer_(panel.2dsmoother(..., n = 200))

Cano-Barbacil, C.; Radinger, J.; Argudo, M.; Rubio-Gracia, F.; Vila-Gispert, A. & García-Berthou, E. 2020. Key factors explaining critical swimming speed in freshwater fish: a review and statistical analysis for Iberian species. Scientific Reports, 10: 1-12. https://doi.org/10.1038/s41598-020-75974-x


148 visualizaciones0 comentarios

Entradas Recientes

Ver todo

Comments


bottom of page