SKmay
SKmay

Reputation: 39

ggplot error with date string on x-axis

I am trying to plot localminute as x-axis and meter_value as y-axis. Dataset has 11.9K rows, here's a snippet:

localminute,dataid,meter_value
2016-01-01 05:18:49.497023-06,35,98178  
2016-01-01 05:45:43.51577-06,35,98182  
2016-01-01 05:57:45.024395-06,35,98184  
2016-01-01 06:08:41.532267-06,35,98186  
2016-01-01 06:36:50.053034-06,35,98188  
2016-01-01 06:56:53.066606-06,35,98192  
2016-01-01 08:57:53.65758-06,35,98212  

I used "ggplot" comment but got error "error in usemethod("depth") :...

test <- read.csv("test_35.csv")  #read data in csv file, to plot data
ggplot(test, aes(x=localminute, y=meter_value)) + geom_point() +
      ggtitle("meter value for dataID=35") +
      theme(axis.text.x = element_text(angle=90, hjust=1))

Error in UseMethod("depth") : 
  no applicable method for 'depth' applied to an object of class "NULL"`

Upvotes: 0

Views: 324

Answers (1)

Carlos Eduardo Lagosta
Carlos Eduardo Lagosta

Reputation: 1001

Specify the format of the variables when reading the file:

test <- read.csv('test_35.csv', colClasses = c('POSIXct','integer','integer'))

Upvotes: 1

Related Questions