Anuj Sharma Anuj Sharma - 8 days ago 6
R Question

Unable to plot column in y axis in R

I have columns in R dataframe as

StreetName BeginTime
wls-wilkeson17-45 2016-11-26 20:04:33
wls-wilkeson17-46 2016-11-26 20:20:06
wls-wilkeson17-49 2016-11-26 21:28:01
wls-wilkeson17-46 2016-11-26 21:33:10
wls-wilkeson17-43 2016-11-26 21:48:56
wls-wilkeson17-46 2016-11-26 21:59:18
wls-wilkeson17-47 2016-11-26 21:07:19


And type of "StreetName" column is "factor". When I am trying to plot this column in y or x axis in R it is showing some numeric values in axis like

2620.0
2620.6
2621.1
2622.3 ......


enter image description here

But I wanted it should show all street names in axis. Can anyone please guide me in right direction?

Plot created by code:

plot(x = user_sig_all$BeginTime, y = user_sig_all$StreetName)

Answer

You can do this easily by using ggplot2.

Try this:

dat <- read.table(header = TRUE, text = "
StreetName             Date       Time
wls-wilkeson17-45      2016-11-26 20:04:33
wls-wilkeson17-46      2016-11-26 20:20:06
wls-wilkeson17-49      2016-11-26 21:28:01
wls-wilkeson17-46      2016-11-26 21:33:10
wls-wilkeson17-43      2016-11-26 21:48:56
wls-wilkeson17-46      2016-11-26 21:59:18
wls-wilkeson17-47      2016-11-26 21:07:19")
dat$BeginTime <- as.POSIXct(paste(dat$Date, dat$Time))
dat

library(ggplot2)
ggplot(dat, aes(x=BeginTime, y = StreetName)) + geom_point()

enter image description here