我正在 Posit Cloud 中绘制来自 .CSV 的非常基本的数据。绘图本身看起来就像我想要的那样,但 x 轴和 y 轴在轴线中间都有一些粗体,我想删除它们。问题可以在下面的第一张图片中看到,我在下面的图片中突出显示了较粗的部分。
重现问题的代码示例,与我的代码相同(减去数据):
#base R plot definition
plot(
#define axes
x= 1:13,
y= 3:15,
#customise axes
xaxs = "i",
yaxs = "i",
type="l",
col="#32a852",
bty = "l",
#labels
xlab = 'Bias Current [mA]',
ylab = "Voltage [V]",
main ="IV Characteristic of 1270nm Laser")
我意识到轴并非都从 0 开始,如果它们都从 0 开始,那么这不会成为问题,但我不想在图中添加死区。
我尝试通过在绘图定义中设置
axes=FALSE
来删除轴,然后单独将轴添加回来,但我最终得到了相同的结果,但以更复杂的方式生成。
问题中的伪影不是粗体l,它在其他轴线上绘制了轴。
这能解决问题吗?改编自这个答案到另一个问题。
plot(
#define axes
x= 1:13,
y= 3:15,
#customise axes
axes = FALSE,
xlim = c(0, 13),
ylim = c(0, 15),
type="l",
col="#32a852",
bty = "l",
#labels
xlab = 'Bias Current [mA]',
ylab = "Voltage [V]",
main ="IV Characteristic of 1270nm Laser")
axis(1, at = c(-1,13), labels = c("",""), lwd.ticks = 0)
axis(1, at = seq(0, 13, by=2), lwd = 0, lwd.ticks = 1)
axis(2, at = c(-1, 15), labels = c("",""), lwd.ticks = 0)
axis(2, at = seq(0, 15, by=2), lwd = 0, lwd.ticks = 1)
创建于 2023-08-14,使用 reprex v2.0.2
问题在于框和轴线的过度绘制。正如评论中提到的,
ragg
包中提供的AGG图形设备可能会解决这个问题。如果没有,您可以绘制不带线条的轴刻度:
plot(
#define axes
x= 1:13,
y= 3:15,
#customise axes
xaxs = "i",
yaxs = "i",
type="l",
col="#32a852",
axes = FALSE,
#labels
xlab = 'Bias Current [mA]',
ylab = "Voltage [V]",
main ="IV Characteristic of 1270nm Laser")
box(bty = "l")
axis(side = 1, lwd = 0, lwd.ticks = 1)
axis(side = 2, lwd = 0, lwd.ticks = 1)