Why is my base R legend taking over half of my graph?

I plotted the following graph:

data(iris)
plot(iris$Sepal.Length, iris$Sepal.Width, col = iris$Species)
legend("topright", legend = levels(iris$Species), col = 1:3, pch = 21)

And my graph ends up looking like this:

Rplot

I'm not sure what is going on. I've asked friends to test the code and they don't run into the same issue. I've also tried restarting R and my laptop.

I get the same thing if my viewer pane is too small when I run the plot commands:
image

Do you know how to resize the pane?

try pressing the zoom button in the plots subwindow of Rstudio.
You could resize the plot with your mouse and see how it looks at different sizes.

Also, you could save the plot to an image of a fixed size, and then view it in the normal way you would view an image file.

data(iris)
png("irisexample.png",width=15,height=15,units="cm",res=200)
plot(iris$Sepal.Length, iris$Sepal.Width, col = iris$Species)
legend("topright", legend = levels(iris$Species), col = 1:3, pch = 21)
dev.off()

This is how the graph looks like when I zoom in.

I'm not sure if it's a setting issue.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

Once you've rendered that graph in the viewer pane, zooming won't change it: Can you resize the viewer pane?

ok, forget the zoom for now, focus on adjusting the grey border around the normal plot window so it has a larget size, and if necessary rerun the plotting code force a redraw.

or go the file (png) approach because that will guarantee whatever size in cm's you tell it, and if its nice and large then you will get the legend comfortable along with that chart info