के साथ सीमा निर्धारित करना मैं समय-श्रृंखला डेटा के साजिश के लिए एक्स-अक्ष के लिए सीमा निर्धारित करना चाहता हूं जिसमें केवल समय (कोई तिथियां नहीं) हैं। मेरे सीमाएं हैं:scale_x_datetime और समय डेटा
lims <- strptime(c("03:00","16:00"), format = "%H:%M")
और मेरे ggplot प्रिंट ठीक, लेकिन जब मैं scale_x_datetime
scale_x_datetime(limits = lims)
में जोड़ना मैं Error: Invalid input: time_trans works with objects of class POSIXct only
की पूरी तरह से प्रतिलिपि प्रस्तुत करने योग्य उदाहरण सौजन्य से How to create a time scatterplot with R?
dates <- as.POSIXct(as.Date("2011/01/01") + sample(0:365, 100, replace=TRUE))
times <- as.POSIXct(runif(100, 0, 24*60*60), origin="2011/01/01")
df <- data.frame(
dates = dates,
times = times
)
lims <- strptime(c("04:00","16:00"), format = "%H:%M")
library(scales)
library(ggplot2)
ggplot(df, aes(x=dates, y=times)) +
geom_point() +
scale_y_datetime(limits = lims, breaks=date_breaks("4 hour"), labels=date_format("%H:%M")) +
theme(axis.text.x=element_text(angle=90))
यह काम करता था लेकिन मुझे तारीख को आज की तारीख में बदलना पड़ा। – raphael
मान्य रूप से मुझे नहीं पता कि POSIXct और POSIXlt के लिए क्या खड़ा है, लेकिन POSIXlt डेटा के साथ, मैं POSIXlt सीमाएं सेट नहीं कर सका। 'त्रुटि: अमान्य इनपुट: time_trans केवल क्लास POSIXct की ऑब्जेक्ट्स के साथ काम करता है 'किसी कारण से, POSIXct ने इस उत्तर में सुझाए अनुसार काम किया। महान सुझाव। – PatrickT