I have a lattice plot, I am trying to change its background but can't seem to make it work. I am also trying to add Custom heatmap labels (ranging from 1 to 5, and would like to add some text. )
par(bg = "yellow")
levelplot(as.matrix(x = c(1:5),y = c(5:1))
)
Thank you for your time!
CodePudding user response:
library(lattice)
trellis.par.set(background = list(col="yellow"))
levelplot(as.matrix(x = c(1:5),y = c(5:1)),
scales=list(x=list(at=1:5, labels=LETTERS[1:5])))
Needless to say, if you are looking for multiple formatting changes, easy annotations, custom scales and rich documentation, you should switch to ggplot:
library(ggplot)
ggplot(data.frame(x = 1:5), aes(x, 0.5, fill = x))
geom_tile()
geom_text(aes(label = x), size = 10)
coord_equal()
scale_x_continuous(limits = c(0.5, 5.5), expand = c(0, 0))
scale_y_continuous(limits = c(0, 1), expand = c(0, 0))
scale_fill_gradient2(low = "#ff77ff", mid = "white", high = "cyan",
midpoint = 3)
theme_classic(base_size = 18)
theme(plot.background = element_rect(fill = "#FFFF80"),
plot.margin = margin(150, 50, 150, 50),
legend.background = element_blank())