我想以 2018-03-28 格式输出日期。当我尝试这样做时,我在折线图中只得到点:
当使用 as.Date 或 strptime(没关系)时,它只给出:jan、feb、mar、apr。但这些线路正在工作:
这是我的代码,用于获取与 jan、feb、mar 一起使用的行。
output$shotAnalyse2 <- renderPlot({
head(rsShotResult)
if(input$shotAnalyse2ShotType == "free_throw"){
position <- 0
updateSelectInput(session, "shotAnalyse2Position", selected = 0)
} else{
position <- input$shotAnalyse2Position
}
ggplot(rsShotResult[rsShotResult$fullname %in% input$shotAnalyse2Players
&
as.Date(rsShotResult$startdate) <= input$shotAnalyse2Date[2]
&
as.Date(rsShotResult$startdate) >= input$shotAnalyse2Date[1]
&
rsShotResult$value3 == position
&
rsShotResult$value4 == input$shotAnalyse2ShotType
, ],
aes(x = strptime(starttime, format="%Y-%m-%d"),
y = percentage)) +
geom_line(aes(colour = as.character(accountid))) +
geom_point(aes(colour = as.character(accountid))) +
xlab("starttime") +
scale_colour_manual(
values = palette("default"),
name = "Players",
breaks = rsShotResult$accountid
)
运行命令时:dput(head(rsShotResult))
我得到这个结果:
structure(list(accountid = c(22, 22, 27, 28, 28, 30), firstname = c("Henk",
"Henk", "Tim", "Dean", "Dean", "Max"), lastname = c("Wilders",
"Wilders", "Sneijder", "Babel", "Babel", "Pele"), starttime = c("2017-12-13",
"2018-03-09", "2017-12-13", "2017-12-13", "2018-03-09", "2017-12-13"
), value = c(16, 7, 41, 7, 19, 16), value2 = c(23, 10, 47, 16,
20, 20), value3 = c("0", "0", "0", "0", "0", "0"), value4 = c("free_throw",
"free_throw", "free_throw", "free_throw", "free_throw", "free_throw"
), startdate = c("2017-12-13", "2018-03-09", "2017-12-13", "2017-12-13",
"2018-03-09", "2017-12-13"), fullname = c("Henk Wilders", "Henk Wilders",
"Tim Sneijder", "Dean Babel", "Dean Babel", "Max Pele"
), percentage = c(69.5652173913043, 70, 87.2340425531915, 43.75,
95, 80), points = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_)), .Names = c("accountid", "firstname", "lastname",
"starttime", "value", "value2", "value3", "value4", "startdate",
"fullname", "percentage", "points"), row.names = c(NA, 6L), class = "data.frame")