ayush
ayush

Reputation: 343

Zooming the ggplot or normal plot in R

I am trying to zoom the plot that I have got. But i couldn't find any proper result. Here is my original plot!

plt <- ggplot(Df, aes(x = Lon, y = Lat, colour = AC), pch = 17) +geom_point()
plt + geom_path(arrow= arrow(), colour="grey") + scale_size(range = 1)

I have tried to do it using dygraph, zoom packages but couldn't succeed. Note that I do not want to use xlim and ylim over here.

Upvotes: 1

Views: 6307

Answers (3)

Nayan Dharamshi
Nayan Dharamshi

Reputation: 33

ggsave(p,filename=mypath,width=13.66,height=7.05,limitsize = FALSE) 

worked for me in getting the zommed plots saved within a loop. p- plot

Upvotes: 0

Mike Wise
Mike Wise

Reputation: 22827

What I do in this case is render it additionally to a png file at high resolution and then I can examine it with other tools at my leisure. Code with filename and 1000x1000 resolution is like this:

   gfname <- sprintf("plotname-%d.png",version)
   png(gfname,width=1000,height=1000)
   print(plt)
   jnk <- dev.off()

Upvotes: 0

RHA
RHA

Reputation: 3862

If i understand correctly, you want to zoom in and out in the graphics device (window) and not zoom the plot itself, as is shown here Limit ggplot2 axes without removing data (outside limits): zoom

Probably you're best bet is still the zoom package. This package has several functions that may be useful to you, like inout.zoom() and sq.zoom(). If this doesn't work for you, please be more specific of what it doesn't do.

R-studio offers some options: 1. There is a zoom button above the plot window, that shows the graph in a bigger window. I some cases this will be enough, however in your case it will not be because you have many points cluttered together. 2. In R-studio, press EXPORT-SAVEtoPDF-PREVIEW. This will open a preview in acrobat reader where you can zoom in and out as much as you like.

Upvotes: 4

Related Questions