0

I have a dataframe with one row, i'd like to show it when the horizontal axis is of type datetime. for some reason when I have a single dot, there are no ticks on the horizontal axis.

table_hr_tags_per_bin <- data.frame(matrix(c("2018-11-21 12:40:35", "25"),nrow = 1,ncol = 2))
colnames(table_hr_tags_per_bin) <-c('StartTimeStamp', 'cars')

plot_conf = ggplot() +
  geom_point(data = table_hr_tags_per_bin, aes_string(x='StartTimeStamp', y= "cars"),colour = "red", size=3) +
  labs(subtitle="plot_name", 
       y="y_axis_name", 
       x="Time", 
       title="my mitle", 
       caption = "") +
  theme(axis.text.x = element_text(angle = 80, hjust = 1)) +
  scale_x_datetime(date_breaks  = paste0(4," sec"), label=function(x) substr(x,12,19))+ 
  scale_y_continuous(breaks=waiver())

plot(plot_conf)

The problematic output is shown below:

enter image description here

Any suggestion would be helpful!

JammingThebBits
  • 732
  • 11
  • 31
  • 2
    Share some sample data to work with. You can use `dput` to share data. – NelsonGon Apr 06 '19 at 18:43
  • 1
    Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Apr 06 '19 at 18:54

1 Answers1

1

Maybe I am wrong in anticipating what you mean, if not, I think your datetime and scale_x_datetime use is not right.

If you use lubridate package and the right format for dates, it probably is much easier to get what you want. I have added a second date with a second value for coming nearer to what you wanted with just showing one single point.

library(lubridate)
df <- tibble(dt=c("2018-11-21T12:40:35", 
                  "2018-11-22T12:41:35"),
             value=c("25", "26"))

ggplot(df %>% filter(dt < "2018-11-22T12:41:35"), aes(dt, value)) + geom_point()
MarBlo
  • 4,195
  • 1
  • 13
  • 27