Search code examples
rggplot2ggmap

Find limits for scale_x or y continous or avoid to remove rows in ggplot2 and ggmap


i also have tried scale_x_continous(limit=c(0,150)) and scale_y_continnous(limit=c(0,150)) +geom_smooth(method='lm') but not getting the points code is

register_google(key=api)
map <- get_googlemap(center = c(104.,1.35), zoom = 10)
ggmap(map)+geom_point(data=cordinate,aes(x=X,y=Y))+
  geom_text_repel(data=cordinate,aes(x=X,y=Y,label=NPCs),fontface='bold')+
  scale_y_continuous(limits = c(0,150))+
  scale_x_continuous(limits = c(0,150))+
  geom_smooth(method = 'lm')

mentioned limits are not working its only showing the map but not showing the points i also reviewed previous question on this platform but could not find working material so google map api is working fine as its showing map but not points. error i am getting is:

Warning messages:

1: Removed 35 rows containing missing values (geom_point).

2: Removed 35 rows containing missing values (geom_text_repel).


Solution

  • Given values in the dateset was out of range and i changed the values by x=y y=x

    map <- get_googlemap(center = c(104.,1.35), zoom = 10)
    
    ggmap(map)+geom_point(data=cordinate,aes(x=Y,y=X))
        +geom_text_repel(data=cordinate,aes(x=Y,y=X,label=NPCs),fontface='bold')
        +scale_y_continuous(limits = c(0,150))
        +scale_x_continuous(limits = c(0,150))+geom_smooth(method = 'lm')
    

    that solved my problem as data was not going out of range after applying this.