在涉及具有 paste() 的向量的基础 R 图中制作粗体轴标题
Making bold axes titles in base R plots involving vectors having paste()
假设我绘制了一个涉及以下代码行的图:
#Sample Code
calc1 <- 1/4
a <- paste(calc1, "X", sep = "")
calc2 <- (1/2)*100
b <- paste(calc2, "%", sep = "")
x <- c(1, 2, 3)
y <- c(4, 5, 6)
#Plot (Regular Axis Titles)
plot(x, y,
xlim = c(1, 3),
xlab = a,
ylim = c(4, 6),
ylab = b)
有没有办法在直接调用具有 paste() 函数的向量时使坐标轴标题加粗?这是我所做的解决方法:
#Plot (Bold Axis Titles, Workaround)
plot(x, y,
xlim = c(1, 3),
xlab = expression(bold("0.25X")),
ylim = c(4, 6),
ylab = expression(bold("50%")))
以下是失败的尝试:
#Attempt 1
plot(x, y,
xlim = c(1, 3),
xlab = expression(bold(a)),
ylim = c(4, 6),
ylab = expression(bold(b)))
#Attempt 2
plot(x, y,
xlim = c(1, 3),
xlab = expression(bold(paste(calc1, "X", sep = ""))),
ylim = c(4, 6),
ylab = expression(bold(paste(calc2, "%", sep = ""))))
这就是为什么我不希望在使用 expression(bold()) 之前手动编码向量的返回元素以进行轴标记的原因:
您可以使用 par(font.lab = 2)
.
设置粗体轴标题
calc1 <- 1/4
a <- paste(calc1, "X", sep = "")
calc2 <- (1/2)*100
b <- paste(calc2, "%", sep = "")
x <- c(1, 2, 3)
y <- c(4, 5, 6)
par(font.lab = 2)
plot(x, y,
xlim = c(1, 3),
xlab = paste(calc1, "X", sep = ""),
ylim = c(4, 6),
ylab = paste(calc2, "%", sep = ""))
假设我绘制了一个涉及以下代码行的图:
#Sample Code
calc1 <- 1/4
a <- paste(calc1, "X", sep = "")
calc2 <- (1/2)*100
b <- paste(calc2, "%", sep = "")
x <- c(1, 2, 3)
y <- c(4, 5, 6)
#Plot (Regular Axis Titles)
plot(x, y,
xlim = c(1, 3),
xlab = a,
ylim = c(4, 6),
ylab = b)
有没有办法在直接调用具有 paste() 函数的向量时使坐标轴标题加粗?这是我所做的解决方法:
#Plot (Bold Axis Titles, Workaround)
plot(x, y,
xlim = c(1, 3),
xlab = expression(bold("0.25X")),
ylim = c(4, 6),
ylab = expression(bold("50%")))
以下是失败的尝试:
#Attempt 1
plot(x, y,
xlim = c(1, 3),
xlab = expression(bold(a)),
ylim = c(4, 6),
ylab = expression(bold(b)))
#Attempt 2
plot(x, y,
xlim = c(1, 3),
xlab = expression(bold(paste(calc1, "X", sep = ""))),
ylim = c(4, 6),
ylab = expression(bold(paste(calc2, "%", sep = ""))))
这就是为什么我不希望在使用 expression(bold()) 之前手动编码向量的返回元素以进行轴标记的原因:
您可以使用 par(font.lab = 2)
.
calc1 <- 1/4
a <- paste(calc1, "X", sep = "")
calc2 <- (1/2)*100
b <- paste(calc2, "%", sep = "")
x <- c(1, 2, 3)
y <- c(4, 5, 6)
par(font.lab = 2)
plot(x, y,
xlim = c(1, 3),
xlab = paste(calc1, "X", sep = ""),
ylim = c(4, 6),
ylab = paste(calc2, "%", sep = ""))