I have tried to plot a series of points in R, and I use type="b"
as a plot option. However, there is a lot of padding (white space) between the points and the lines between them, so much that the line disappears entirely between some points. Her is a picture of how it looks:
I have tried to make the points smaller with the cex
plot option, but this does not help, as it only changes the size of the points and not where the lines between the points between these starts and ends. I do not know if this makes a difference, but the symbols I am using are pch=1
.
I am interested in knowing if it is possible to reduce this padding, and how you do so. I am not interested in using type=o
as a plot option instead.
The basic plot command Here, we use type="l" to plot a line rather than symbols, change the color to green, make the line width be 5, specify different labels for the x and y axis, and add a title (with the main argument).
Use par(mai = c(bottom, left, top, right)) before the plot. It will create extra space around the plot area.
Any particular reason why you don't want to use type="o"
? It seems like the easiest way to get the effect you want:
# Fake data
set.seed(10)
dfs = data.frame(x=1:10, y=rnorm(10))
plot(y~x,data=dfs, type="o", pch=21, bg='white')
pch=21
is a circle marker like pch=1
, but with both border and fill. We set the fill to white with bg="white"
to "cover up" the lines that go through the point markers.
You can also use cex
to change the marker size to avoid overlap and make the lines between nearby points visible:
set.seed(10)
dfs = data.frame(x=1:100, y=cumsum(rnorm(100)))
plot(y~x,data=dfs, type="o", pch=21, bg="white", cex=0.6)
Using a dataframe named dfs
this seems to deliver a mechanism for adjusting the surrounding "white halo" to whatever size of point an halo you want by adjusting the 'cex' values of the white and black points :
plot(y~x,data=dfs, type="l")
with(dfs, points(x,y, pch=16,col="white",cex=1.4))
with(dfs, points(x,y,cex=1) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With