Programmers learn & share
0 votes

Problem :

I am getting error while using ggplot2 to plot the graphs

error in usemethod("depth") : no applicable method for 'depth' applied to an object of class "null"

by (6.9k points)  
edited by | 163 views

1 Answer

0 votes

Solution :

Bellow solution should work:

 scale_x_datetime(date_breaks = "1 day", date_labels = "%d/%m/%Y %H:%M:%S", minor_breaks = NULL) +

If plotly is not working for you then there are a few more ways that you could zoom in on your data.

  1. Filter at the source: you could filter in the data as it goes into ggplot.
a <- ggplot(test3a %>% 
         filter(localminute >= ymd(20151001),
                localminute <= ymd(20151031)),
       aes(x = localminute, y = meter_value)) + 
  1. Set limits in scale_x_datetime: This has the same result as filtering the data.
 scale_x_datetime(date_breaks = "1 day", date_labels = "%d/%m %Y %H:%M:%S", minor_breaks = NULL,
                   limits = c(ymd_hm(201510010000), ymd_hm(201510022359))) +
  1. Use coord_cartesian:  It preserves other data that's out of range for your other layers to use, even if you're not showing it. For instance, if you had a geom_smooth layer, you'd want to use this option...
coord_cartesian(xlim = c(ymd_hm(201510010000), ymd_hm(201510011000))) +

by (36.1k points)  
2,183 questions
2,486 answers
241 users