简体   繁体   中英

Setting the size of the graphics window (plot size) in R

plot.new()
segments(0, 1, 3)
segments(0, 0.5, 2)

I tried plotting 2 lines, but it seems like my plot size is too small (so the two lines appear to be the same length). I've tried the following in reference to this post but couldn't get the desired result:

> dev.new(height = 3, width = 3)
NULL
> segments(0, 1, 3)
Error in segments(0, 1, 3) : plot.new has not been called yet
> segments(0, 0.5, 2)
Error in segments(0, 0.5, 2) : plot.new has not been called yet

You can initialize an empty plot and then put your line segments into this plot:

# empty plot
plot(NULL, ylim=c(-1,2), xlim=c(-1,4), ylab="something", xlab="the x axis")
# add line segments
segments(0, 1, 3)
segments(0, 0.5, 2)

This produces

在此处输入图片说明

To remove everything except the line segments, start with

plot(NULL, ylim=c(-1,2), xlim=c(-1,4), ylab="", xlab="", xaxt="n", yaxt="n", bty="n")

You can find references to each of these arguments in the help(par) file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM