0

我想在 R 中创建一个黑白图,在同一个图上绘制 4 个不同的变量。

该图非常小,因此我不想使用 type="o" 或其他默认类型。

相反,我想要简单的细线,虚线,粗线,粗虚线,有什么办法吗?对于黑白图时使用的最佳符号,您还有其他建议吗?

4

4 回答 4

2

?par会给你几乎所有的信息

基本上你需要的是:

  • lty指定线型
  • lwd指定线宽
  • col指定颜色(另见rgb

另请参阅此页面上的 Quick-R 图形参数。

于 2013-05-01T16:05:27.110 回答
2

是的,当然这是可能的。你应该使用lty代码。例如,如果你想表示两个变量,你应该尝试lty=c(1, 23). 您可以尝试不同的数字组合。要绘制更粗的线,lwd命令应该会有所帮助。检查下面的链接以获取更多详细信息。

http://stat.ethz.ch/R-manual/R-patched/library/graphics/html/par.html

于 2013-05-01T16:12:21.540 回答
0

研究和的lty论点。plot()lines()

于 2013-05-01T15:57:25.077 回答
0

R中带有多条线的黑白线图。

# Generate some data
x<-1:25; 
y1<-c(0.966,    0.8491, 0.7923, 0.7488, 0.7176, 0.6905, 0.6693, 0.6552, 0.6397, 0.6295, 0.616,  0.6081, 0.6002, 0.5915, 0.5839, 0.5773, 0.5704, 0.563,  0.5563, 0.5508, 0.5435, 0.5405, 0.5328, 0.5281, 0.522); 
y2<-c(0.7925,   0.75,   0.7269, 0.6868, 0.7097, 0.6695, 0.6517, 0.6531, 0.6698, 0.6375, 0.641,  0.6427, 0.6347, 0.633,  0.628,  0.6251, 0.6291, 0.6305, 0.6517, 0.63,   0.6363, 0.6224, 0.6257, 0.6364, 0.6322);
y3<-c(0.8925,   0.85,   0.8269, 0.7868, 0.7097, 0.7695, 0.5517, 0.6531, 0.5698, 0.5375, 0.541,  0.5427, 0.5347, 0.533,  0.528,  0.5251, 0.5291, 0.5305, 0.5517, 0.53,   0.5363, 0.5224, 0.5257, 0.5364, 0.5322);

# Give a name for the chart file
png(file = "line_plot.png", width = 500, height = 300)

# Display the line plot in black and white with multiple lines.
plot(x, y1, type="b", pch=19, col="black", xlab="X-Label", ylab="Y-label", lwd = 1, cex=1)

# Add a line
lines(x, y2, pch=18, col="black", type="b", lty="dashed", lwd = 1)

# Add another line
lines(x, y3, pch=16, col="black", type="b", lty="dotted", lwd = 1)

# Add a legend
legend(19, 0.95, legend=c("Algorithm1", "Algorithm2", "Algorithm3" ), col=c("black", "black", "black"), lty=1:3, cex=1, box.lty=1, box.lwd=1, box.col="black")

# Save the file
dev.off()

输出:

黑白线图

于 2018-10-20T09:55:11.167 回答