简体   繁体   English

将 plotly 与 ggplot (R) 一起使用

[英]Using plotly with ggplot (R)

I'm trying to integrate plotly in my code but the final result is different than what I get with ggplot.我正在尝试将 plotly 集成到我的代码中,但最终结果与我使用 ggplot 得到的结果不同。

I'm plotting temperature and humidity (from a data frame df ) measurements taken in regular time intervals and saving it into an object that I plot again using plotly, like so:我正在绘制以固定时间间隔进行的温度和湿度(来自数据帧df )测量值,并将其保存到 object 中,我再次使用 plotly 再次使用 plot,如下所示:

april_temp <- df %>%
  filter(!is.na(temp) &
  day >= '2020-04-01' &
  day <= '2020-04-30') %>%
  ggplot(aes(hour, temp, color = temp, group =  day)) +
  geom_line() +
  geom_point(size = 0.8) +
  scale_color_gradient(low = 'blue', high = 'orange') +
  facet_wrap(vars(dia))

This code, generates the following graphic(as expected): Daily temperatures from April此代码生成以下图形(如预期):从 4 月开始的每日温度

Plotly official documentation says that I can just plot I again by calling ggplotly() , like so: Plotly 官方文档说我可以通过调用ggplotly()再次调用 plot ,如下所示:

ggplotly(april_temp)

For some reason plotly is connecting points that have the same value instead of connecting them as a time series like before.出于某种原因,plotly 正在连接具有相同值的点,而不是像以前那样将它们连接为时间序列。 It looks like this: Same plot, different result它看起来像这样:相同的 plot,不同的结果

What am I missing?我错过了什么?

Your ggplot object is named abril_temp .您的ggplot object 被命名为abril_temp Just a typo.只是一个错字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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