dbr
dbr

Reputation:

black and white line plot in R

I would like to create a black and white plot in R with 4 different variables plotted on the same figure.

The plot is very small therefore I would not like to use type="o" or other default types.

Instead I would like to have simple thin line, dashed line, thick line, thick dashed line, is there any way to do this? Do you have any other suggestions for the best symbols to use when plots are in black and white?

Upvotes: 0

Views: 3448

Answers (4)

Ashok Kumar Jayaraman
Ashok Kumar Jayaraman

Reputation: 3095

The black and white line plot in R with multiple lines.

# 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()

Output:

The line plot in black and white

Upvotes: 0

Vara
Vara

Reputation: 245

Yes of course it is possible. You should uselty code. For example, if you want to represent two variables, you should try lty=c(1, 23). You can try different combination of numbers. To plot thicker lines, lwd command should help. Check the link below for more details.

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

Upvotes: 2

Sycorax
Sycorax

Reputation: 1386

Look into the lty argument of plot() and lines().

Upvotes: 0

nico
nico

Reputation: 51690

?par will give you pretty much all the information on this

Essentially what you need is:

  • lty to specify line type
  • lwd to specify line width
  • col to specify the color (see also rgb)

See also this page on graphical parameters on Quick-R.

Upvotes: 2

Related Questions