首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >创建循环图

创建循环图
EN

Stack Overflow用户
提问于 2017-11-11 22:37:27
回答 2查看 455关注 0票数 2

我希望在几个月内创建一个小时的循环图。我希望它看起来像下面的情节。我的目标是用一条水平线表示每个月的平均温度,然后在每个月内用图表显示该月典型日期的温度波动。我尝试使用monthplot(),但它似乎不起作用:

代码语言:javascript
运行
复制
library(nycflights13)

tempdata <- weather %>% group_by(hour) 

monthplot(tempdata, labels = NULL, ylab = "temp")

它一直显示argument is not numeric or logical: returning NA,但我不确定代码出了什么问题。

EN

回答 2

Stack Overflow用户

发布于 2017-11-11 22:53:29

希望这个ggplot2解决方案能起作用:

代码语言:javascript
运行
复制
library(nycflights13)
library(ggplot2)
library(dplyr)

# Prepare data
tempdata <- weather %>% 
    group_by(month, day) %>%
    summarise(temp = mean(temp, na.rm = TRUE))
meanMonth <- tempdata %>%
    group_by(month) %>%
    summarise(temp = mean(temp, na.rm = TRUE))

# Plot using ggplot2
ggplot(tempdata, aes(day, temp)) +
    geom_hline(data = meanMonth, aes(yintercept = temp)) +
    geom_line() +
    facet_grid(~ month, switch = "x") +
    labs(x = "Month",
         y = "Temperature") +
    theme_classic() +
    theme(axis.ticks.x = element_blank(),
          axis.text.x = element_blank(),
          axis.line.x = element_blank())

票数 4
EN

Stack Overflow用户

发布于 2017-11-12 00:04:40

temp缺少一个值,这会导致错误。您还需要设置timesphase参数。

代码语言:javascript
运行
复制
library(nycflights13)

# Find mean value : this automatically removes the observation with missing data that was causing an error
tempdata <- aggregate(temp ~ month + day, data=weather, mean) 

with(tempdata, monthplot(temp, times=day , phase=month, ylab = "temp"))

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47239057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档