使用 xyplot 和 doubleYscale 更改轴标签颜色和图例线条颜色
Change axis label colors and legend line colors using xyplot and doubleYscale
我正在尝试使用 latticeExtra 的 xyplot 和 doubleYscale 函数创建一个双 y 轴图。如何将左右 y 轴的轴标签颜色以及图例线条颜色更改为与绘图中的线条颜色相同?这些现在以蓝色和粉红色绘制,但应与下图中的线条相同。请参阅下面的可重现代码示例和绘图:
library(lattice)
library(latticeExtra)
# Create the data frame.
My_DataFrame <- data.frame(
emp_id = c (1:5),
salary = c(623.3,515.2,611.0,729.0,843.25),
weight = c(80,90,92,93,91),
start_date = as.Date(c("2012-01-01", "2013-09-23", "2014-05-11", "2014-11-15","2015-03-27")),
stringsAsFactors = FALSE
)
# Print the data frame.
print(My_DataFrame)
obj1 <- xyplot(salary ~ start_date, My_DataFrame, type = "l", lwd = 2, col = "#6F99ADFF", col.lab = "black", ylim = seq(0,1000,100), scales = list(x=list(cex=1.2), y=list(cex=1.2)), xlab = list("", fontsize = 22), ylab = list("Hello", fontsize = 18), ylab.right = list("There", fontsize = 18))
obj2 <- xyplot(weight ~ start_date, My_DataFrame, type = "l", lwd = 2, col = "#E18727FF")
doubleYScale(obj1, obj2, col = c("#6F99ADFF","#E18727FF"), text = c("salary", "weight"), add.ylab2 = FALSE)
添加
par.settings = list(superpose.line = list(col=c("#6F99ADFF", "#E18727FF"))),
在您的代码中:
obj1 <- xyplot(salary ~ start_date, My_DataFrame, type = "l", lwd = 2,
col = "#6F99ADFF", col.lab = "black",
par.settings = list(superpose.line = list(col=c("#6F99ADFF", "#E18727FF"))),
ylim = seq(0,1000,100),
scales = list(x=list(cex=1.2),
y=list(cex=1.2)),
xlab = list("", fontsize = 22),
ylab = list("Hello", fontsize = 18, col="#6F99ADFF"), ylab.right = list("There", fontsize = 18, col="#E18727FF"))
obj2 <- xyplot(weight ~ start_date, My_DataFrame, type = "l", lwd = 2, col = "#E18727FF")
doubleYScale(obj1, obj2, col = c("#6F99ADFF","#E18727FF"), text = c("salary", "weight"), add.ylab2 = F)
我正在尝试使用 latticeExtra 的 xyplot 和 doubleYscale 函数创建一个双 y 轴图。如何将左右 y 轴的轴标签颜色以及图例线条颜色更改为与绘图中的线条颜色相同?这些现在以蓝色和粉红色绘制,但应与下图中的线条相同。请参阅下面的可重现代码示例和绘图:
library(lattice)
library(latticeExtra)
# Create the data frame.
My_DataFrame <- data.frame(
emp_id = c (1:5),
salary = c(623.3,515.2,611.0,729.0,843.25),
weight = c(80,90,92,93,91),
start_date = as.Date(c("2012-01-01", "2013-09-23", "2014-05-11", "2014-11-15","2015-03-27")),
stringsAsFactors = FALSE
)
# Print the data frame.
print(My_DataFrame)
obj1 <- xyplot(salary ~ start_date, My_DataFrame, type = "l", lwd = 2, col = "#6F99ADFF", col.lab = "black", ylim = seq(0,1000,100), scales = list(x=list(cex=1.2), y=list(cex=1.2)), xlab = list("", fontsize = 22), ylab = list("Hello", fontsize = 18), ylab.right = list("There", fontsize = 18))
obj2 <- xyplot(weight ~ start_date, My_DataFrame, type = "l", lwd = 2, col = "#E18727FF")
doubleYScale(obj1, obj2, col = c("#6F99ADFF","#E18727FF"), text = c("salary", "weight"), add.ylab2 = FALSE)
添加
par.settings = list(superpose.line = list(col=c("#6F99ADFF", "#E18727FF"))),
在您的代码中:
obj1 <- xyplot(salary ~ start_date, My_DataFrame, type = "l", lwd = 2,
col = "#6F99ADFF", col.lab = "black",
par.settings = list(superpose.line = list(col=c("#6F99ADFF", "#E18727FF"))),
ylim = seq(0,1000,100),
scales = list(x=list(cex=1.2),
y=list(cex=1.2)),
xlab = list("", fontsize = 22),
ylab = list("Hello", fontsize = 18, col="#6F99ADFF"), ylab.right = list("There", fontsize = 18, col="#E18727FF"))
obj2 <- xyplot(weight ~ start_date, My_DataFrame, type = "l", lwd = 2, col = "#E18727FF")
doubleYScale(obj1, obj2, col = c("#6F99ADFF","#E18727FF"), text = c("salary", "weight"), add.ylab2 = F)