Getting red of the margins while plotting the grid in ggplot

when I plot the grid there are some margins that I don't want it to be visible in my plot. how can I solve this problem?
here is an example:

Grid coordinates

grd.coor<- data.frame(lon=rep(seq(13,16.5,0.5), 13),lat=rep(seq(91,97,0.5),each=8))

library(ggplot2)
ggplot(grd.coor, aes(x=lon, y=lat))+geom_point()+
theme(panel.grid.minor = element_line(colour="white", size=0.5)) +
scale_y_continuous(minor_breaks = seq(91 , 97, .5), breaks = seq(91, 97, .5))+
scale_x_continuous(minor_breaks = seq(13,16.5,0.5), breaks = seq(13,16.5,0.5))

After running this code I get this plot

I want only the area inside the red square to be displayed without the margins.

If you definte grd.coor like this, do you get what you want?

grd.coor<- 
  data.frame(
    lon=rep(seq(13.5,16,0.5), 11),
    lat=rep(seq(91.5,96.5,0.5),each=6)
    )

unfortunately it doesn't work, can you suggest something else which gives the desired outcome

It's not clear what it is you're hoping for -- could you produce an image that shows exactly what you want?

Not sure how to modify theme() arguments to do this, but here's a possibility:

ggplot(grd.coor, aes(x=lon, y=lat))+
  theme_minimal() +
  geom_rect(
    aes(xmin = min(lon), xmax = max(lon), ymin = min(lat), ymax = max(lat)),
    fill = 'grey90'
    ) +
  geom_vline(aes(xintercept = lon), color = 'white', 'size' = 0.5) +
  geom_hline(aes(yintercept = lat), color = 'white', 'size' = 0.5) +
  geom_point()+
  scale_y_continuous(minor_breaks = seq(91 , 97, .5), breaks = seq(91, 97, .5))+
  scale_x_continuous(minor_breaks = seq(13,16.5,0.5), breaks = seq(13,16.5,0.5))
1 Like

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