简体   繁体   中英

R/Shiny Plotly Proportional X-Axis Date Plotting

Could anyone please tell how I can plot proportional x-axis when plotting by dates-see attached?

在此处输入图片说明

You could use the sequence of numbers 1,2,3,... until nrow(df) as x variable, and supply your own tick marks. Example:

df = data.frame(date=c("1 Aug","1 Aug","2 Aug","3 Aug"),value=c(1,1.2,2,4))

plot_ly(df, x =1:nrow(df),
        y =~value,type="scatter",
        mode="lines") %>%
  layout(xaxis=list(tickmode = 'array',
                    tickvals = 1:nrow(df),
                    ticktext = df$date,
                    range = c(0.5, nrow(df)+0.5)))

Result:

在此处输入图片说明

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM