[英]R lattice levelplot, changing the background color and custom colorscale labels
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])))
由reprex package (v2.0.1) 創建於 2022-04-26
與ggplot
一樣, lattice
是基於網格圖形,而不是基於 R 圖形,因此設置par
不會有任何影響。 您可以更改晶格參數,或者您可以在事后使用grid.edit
進行更改:
library(lattice)
library(grid)
levelplot(as.matrix(x = c(1:5), y = c(5:1)))
grid.edit("plot_01.background", gp = gpar(fill = "yellow"))
不用說,如果您正在尋找多種格式更改、簡單的注釋、自定義比例和豐富的文檔,您應該切換到 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())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.