Add Space Between Panels of Openair windRose Plots - r

I created some windrose plots using the openair package and I'm pretty happy with how they turned out but aesthetically it would be nice to have some space between panels. Here's an example:
# windrose plot----
library(openair)
data("mydata")
windRose(mydata[1:144,], ws="ws", wd="wd",
paddle = F,
type = 'weekday',
key.header = 'Wind Speed (m/s)',
key.footer = "",
annotate = F,
angle = 30, # angle of "spokes"...sort of bins for wind direction
cols = 'jet',
key.position = 'right',
dig.lab = 2,
statistic = 'prop.count', #“prop.count” sizes bins according to the
# proportion of the frequency of measurements
fontsize = 20,
grid.line = 100,
max.freq = 105, # maximum value for the radial limits
key = list(header = "Wind Speed (m/s)",
footer = '',
labels = c('0 to 2', '2 to 4',
'4 to 6','6 or more'),
breaks = c(0,2,4,6)),
layout = c(6,1)
)
Anyone have any ideas of how to add space between the panels?

After some digging I found that this plot function utilizes trellis plots, here is a good rundown on them: https://www.stat.auckland.ac.nz/~ihaka/787/lectures-trellis.pdf
Specifically the xyplot function is used to create the trellis plot. The help documentation for ?xyplot shows that you can adjust the argument between to achieve spacing between panels. The between argument is a list containing x and y values that represent space between panels. Therefore we can adjust the above code simply by adding the argument between = list(x=0.25, y = 0.25) and can adjust x and y to our preference like this:
library(openair)
data("mydata")
windRose(mydata[1:144,], ws="ws", wd="wd",
paddle = F,
type = 'weekday',
key.header = 'Wind Speed (m/s)',
key.footer = "",
annotate = F,
angle = 30, # angle of "spokes"...sort of bins for wind direction
cols = 'jet',
key.position = 'right',
dig.lab = 2,
statistic = 'prop.count', #“prop.count” sizes bins according to the
# proportion of the frequency of measurements
fontsize = 20,
grid.line = 100,
max.freq = 105, # maximum value for the radial limits
key = list(header = "Wind Speed (m/s)",
footer = '',
labels = c('0 to 2', '2 to 4',
'4 to 6','6 or more'),
breaks = c(0,2,4,6)),
layout = c(6,1),
between = list(x=0.25, y=0.25)
)

Related

how to make calculation for y value in tooltip in sparkline in r

I am trying to show ranking in line and increase in number means a decrease in rank. That's why to visualize this relation I multiple rank values with minus 1. However, in tooltip it shows up with minus sign and I can't make calculations in double curly braces. Code is below.
library(data.table)
library(sparkline)
library(tidyverse)
library(DT)
vec_line <- data.table(rank = c(3,2,6,7), cur_year=c(2001,2002,2003,2004))
line = spk_chr(-vec_line[,rank],
type="line",
chartRangeMin = min(-vec_line[,rank]),
chartRangeMax = max(-vec_line[,rank]),
xvalues = vec_line[,cur_year],
tooltipFormat= sprintf('<span style=\"color: {{color}}\">●</span> Year {{x}}: {{y}}.'),
numberDigitGroupSep = "",
width = 150,
height = 50,
lineColor = '#896B84',
fillColor = NULL,
lineWidth = 2)
datatable(data.table(graph = line),
escape = F,
options = list(fnDrawCallback = htmlwidgets::JS('function(){HTMLWidgets.staticRender();}')))%>%
spk_add_deps()

R how to increase distance between grids when using plot function?

I'm learning the Numerical Ecology with R. However, I found all my plots lacking the distance between bars or grids.
myplot
textbook's plot
spe.KM.cascade <-
cascadeKM(
spe.norm2,
inf.gr = 2,
sup.gr = 10,
iter = 100,
criterion = "ssi"
)
dev.new(
title = "CascadeKM",
width = 10,
height = 6,
noRStudioGD = TRUE
)
plot(spe.KM.cascade, sortg = TRUE, border = 'white')
I want to know how to add white borders for every grid.

How do I make a facet/panels of two interaction graphs using lattice in R? [duplicate]

This question already has answers here:
Lattice: multiple plots in one window?
(3 answers)
What is the equivalent of facet_wrap in Lattice
(1 answer)
Closed 4 years ago.
I have this code in R:
xyplot(remove_SMO ~ A, groups = C,
type="a",
ylab="Remoção de óleo (%)",
xlab = "pH",
auto.key = list(space = "right", points = FALSE, lines = TRUE))
And this similar one:
xyplot(remove_SMO ~ B, groups = E,
type="a",
ylab="Remoção de óleo (%)",
xlab = "Temperatura",
auto.key = list(space = "right", points = FALSE, lines = TRUE))
How could I do something like this using lattice, grouping these two interaction graphs?
*The order of the graphics does not matter.
And what good material to learn how to edit graphs developed in lattice? Note that the split command for multiples plots helps but is not ideal, and there is difference in the positioning of the legend for the pink and blue lines. The "facet_wrap" with | is also different, as it greatly changes the aesthetics.
My code for the example.
if(!require("FrF2")) install.packages("FrF2") ; library(FrF2)
if(!require("lattice")) install.packages("lattice") ; library(lattice)
plan.person = FrF2(nfactors = 5,
resolution = 5,
replications = 2,
randomize = FALSE,
factor.names = list(
A = c(3, 9),
B = c(5, 30),
C = c(0.05, 0.5),
D = c(50, 350),
E = c(100, 200)
))
remove_SMO <- c(94.80, 23.40, 99.60, 38.00, 80.20, 27.00, 96.40, 60.00, 99.90, 9.10,
98.40, 37.10, 99.77, 51.70, 97.40, 58.00, 95.10, 25.00, 99.50, 39.10,
80.60, 28.00, 96.70, 61.20, 99.70, 10.00, 98.80, 37.40, 99.40, 52.00,
97.70, 58.40)
plan.atualizado1 = add.response(design = plan.person, response = remove_SMO)
attach(plan.atualizado1)

R igraph Format Date on axis

In the following igraph there are dates to be plotted as marks on the x-axis. Below I provided an example. As the dates are specified in the label matrix they are formatted into an atomic value. How do I get the dates on the x-axis to be displayed in a regular date format?
library(igraph)
nodes=data.frame(
c(0,1,2,3),
c("A","B","C","D")
)
colnames(nodes) = c("id","name")
links = data.frame(
c(0,0,1,2),
c(1,2,3,3)
)
colnames(links) = c("from","to")
layout = matrix(
c(as.Date('2010-01-01'),1, as.Date('2010-01-02'),1, as.Date('2010-01-02'),2, as.Date('2010-01-06'),1), byrow = TRUE, nrow=4
)
net = graph.data.frame(links, vertices = nodes)
plot.igraph(
net, xaxt="n",layout=layout,axes=TRUE,asp=0, rescale=FALSE,xlim=c(as.Date('2010-01-01'),as.Date('2010-01-06')),ylim=c(1,2)
)
You can replace the axis by your own values as explained here.
Using your code, it gives:
layout <- data.frame(Date = as.Date(c('2010-01-01','2010-01-02','2010-01-02','2010-01-06')), value = c(1,2,1,1))
plot.igraph(
net,
layout = layout,
rescale = FALSE,
axis = FALSE,
asp = 0,
xlim = as.Date(c('2010-01-01', '2010-01-06')),
ylim = c(1,2)
)
axis(1, at = as.numeric(layout$Date), labels = layout$Date, cex.axis = 0.9)
axis(2, at = 1:max(layout$value), labels = 1:max(layout$value))

turn off grid lines for R xyplot timeseries

I am plotting a time series with the timePlot function of the open air package of R. The graph has grey grid lines in the background that I would like to turn off but I do not find a way to do it. I would expect something simple such as grid = FALSE, but that is not the case. It appears to be rather complex, requiring the use of extra arguments which are passed to xyplot of the library lattice. I believe the answer lies some where in the par.settings function but all attempts have failed. Does anyone have any suggestions to this issue?
Here is by script:
timeozone <- import(i, date="date", date.format = "%m/%d/%Y", header=TRUE, na.strings="")
ROMO = timePlot(timeozone, pollutant = c("C7", "C9", "C10"), group = TRUE, stack = FALSE,y.relation = "same", date.breaks = 9, lty = c(1,2,3), lwd = c(2, 3, 3), fontsize = 15, cols = c("black", "black"), ylab = "Ozone (ppbv)")
panel = function(x, y) {
panel.grid(h = 0, v = 0)
panel.xyplot(x,y)
}

Resources