我已经创建了该图,但是我想在x轴上将Time
和Date
组合在一起。 (请注意,在我的数据集中,Time
和Date
在单独的列中):
代码:
library(shiny)
library(shinydashboard)
library(ggplot2)
library(scales)
shinyServer(function(input,output){
output$Histogram <- renderPlot({
Energy <- read.csv("Energy.csv")
Energy$Date <- as.POSIXct(Energy$Date)
ggplot(data=Energy, mapping=aes(x=Date, Time, y=kWh)) +
scale_x_datetime(date_breaks= "1 month") +
geom_point(aes(color=Time)) +
theme(axis.text.x = element_text(angle = 25, vjust = 1.0, hjust = 1.0))
})
我该怎么做才能在x轴上同时显示“时间”和“日期”?
答案 0 :(得分:0)
如@ r2evans所述,您应该结合时间和日期,例如
library(dplyr)
Energy <- Energy %>%
mutate(DateTime = lubridate::ymd_hm(paste(Date, Time))
,然后将DateTime用作x轴。