- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
DATE obs1 obs2 obs3
1981-01-01 2032.409 3142.46 1741.143
1981-01-02 2023.687 3870.04 1735.256
1981-01-03 2014.274 4126.25 1728.556
1981-01-04 2005.795 2615.91 1722.985
1981-01-05 2000.674 2940.83 1722.317
1981-01-06 1998.477 3258.69 1723.937
1981-01-07 1997.014 3371.6 1724.104
1981-01-08 1995.576 3184.13 1722.624
1981-01-09 1993.706 3540.76 1719.592
1981-01-10 1991.286 3312.43 1715.156
1981-01-11 1988.633 3028.65 1710.141
1981-01-12 1986.147 3212.79 1705.183
1981-01-13 1984.229 3193.23 1700.789
1981-01-14 1982.756 3294.52 1697.785
1981-01-15 1981.548 3553.78 1696.068
1981-01-16 1980.561 3492.28 1694.544
1981-01-17 1979.792 2452.09 1692.36
1981-01-18 1979.224 1873.82 1689.525
1981-01-19 1978.845 3218.28 1686.452
我需要在 R 中为每日数据绘制季节性(冬季、 Spring 、夏季和秋季)箱线图,如上所示。对于不同的电台,我有 10 年以上格式的数据。情节应该在一个图中,每个季节有多个箱线图。
最佳答案
使用 tidyverse
和 lubridate
的解决方案。 tidyverse
包括用于执行数据整理的 dplyr
和 tidyr
,以及用于创建绘图的 ggplot2
。 lubridate
用于处理数据框中的日期。
由于您提供的数据集不是很有用,因为它仅包含 1 月份的几条记录,因此无法创建显示季节性差异的箱线图,因此我决定创建一个新的示例数据框。我的示例数据框的结构与您的数据集相似,它应该会为您提供一些提示,作为您解决实际问题的起点。
# Set the seed for reproducibility
set.seed(123)
library(tidyverse)
library(lubridate)
# Create example data frame
dt <- data_frame(DATE = seq(ymd("1980-01-01"), ymd("1989-12-31"), by = 1)) %>%
mutate(obs1 = rnorm(nrow(.), mean = 0, sd = 1),
obs2 = rnorm(nrow(.), mean = 1, sd = 2),
obs3 = rnorm(nrow(.), mean = 2, sd = 3))
head(dt)
# # A tibble: 6 x 4
# DATE obs1 obs2 obs3
# <date> <dbl> <dbl> <dbl>
# 1 1980-01-01 -0.56047565 0.7874145 2.7827006
# 2 1980-01-02 -0.23017749 0.1517417 8.5720252
# 3 1980-01-03 1.55870831 0.7193725 1.3293478
# 4 1980-01-04 0.07050839 0.5454177 0.3253155
# 5 1980-01-05 0.12928774 1.4101239 6.1245771
# 6 1980-01-06 1.71506499 -0.6491910 4.5034395
tail(dt)
# # A tibble: 6 x 4
# DATE obs1 obs2 obs3
# <date> <dbl> <dbl> <dbl>
# 1 1989-12-26 -0.3629796 0.6750946 0.8586325
# 2 1989-12-27 0.1102218 2.8572337 9.8541328
# 3 1989-12-28 -0.2700741 1.7614026 1.9109596
# 4 1989-12-29 0.6920973 0.5275611 -0.4756240
# 5 1989-12-30 0.9282803 1.3811225 1.5222535
# 6 1989-12-31 0.5931301 -1.6638739 4.1157087
示例数据框包含 10 年的记录和 3 个观察组。每列的值服从具有不同均值和标准差的正态分布。
第一步是通过将数据集从宽格式转换为长格式来处理数据框,并添加一个显示季节信息的列。
dt2 <- dt %>%
# Convert data frame from lwide format to long format
gather(Observation, Value, -DATE) %>%
# Remove "obs" in the Observation column
mutate(Observation = str_replace(Observation, "obs", "")) %>%
# Convert the DATE column to date class
mutate(DATE = ymd(DATE)) %>%
# Create Month column
mutate(Month = month(DATE)) %>%
# Create Season column
mutate(Season = case_when(
Month %in% c(12, 1, 2) ~ "winter",
Month %in% c(3, 4, 5) ~ "spring",
Month %in% c(6, 7, 8) ~ "summer",
Month %in% c(9, 10, 11) ~ "fall",
TRUE ~ NA_character_
))
之后,我们可以使用 ggplot2
来创建箱线图。请注意,我使用 stat_summary
向每个组添加一条红线以表示平均值。
# Create a boxplot using ggplot2
# Specify the aesthetics
ggplot(dt2, aes(x = Season, y = Value, fill = Observation)) +
# Specify the geom to be boxplot
geom_boxplot() +
# Add a red line to the mean
stat_summary(aes(ymax = ..y.., ymin = ..y..),
fun.y = "mean",
geom = "errorbar", # Use geom_errorbar to add line as mean
color = "red",
width = 0.7,
position = position_dodge(width = 0.75), # Add the line to each group
show.legend = FALSE)
关于r - R 或 matlab 中的季节性箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47613708/
我正在练习课本上的练习,但无法获得应有的输出。 这是我所拥有的: #include #include #include //Initialize OpenGL void init(void) {
我有一系列的点,我将把它们变成图表上的一条线。我想要的是给图表下方的区域进行渐变填充。它看起来有点类似于这样的彭博图表; 我的问题实际上分为三个部分; 首先,我应该如何只填充图表下方的区域? 第二,如
我正在尝试根据数组中保存的数据绘制折线图。我已经成功绘制了 X 轴和 Y 轴。然而,当我在图表上绘制带有数据的线时,它与 X 轴和 Y 轴值不对齐。我不确定如何解决这个问题。我已经展示了下面的代码:
我有一个对象 DataEntry 定义如下: public class DataEntry { private long timestamp; private double value; public
我正在使用 MPAndroidChart-v2.1.6,我面临以下问题。 当我有一个数据条目时,它开始在 X 轴上显示从 0 索引开始的值。这就是它的样子。 当我只有一个数据输入时,我希望它居中对齐,
我有一个 pandas 数据框,看起来像这样 - Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Marks 0 30 31 29 1
enter image description here嗨, 我正在尝试重新创建我们看到的一些 covid-19 图表。我正在使用来自约翰霍普金斯大学数据库的数据。 数据的排列方式是城市名称在行中,列
我正在使用 Pandas 来绘制一些数据。 如果我绘制这个: import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame
当我使用 Seaborn 在同一轴上绘制多个线图时,不会创建任何图例。即使我在 sns.lineplot 中为图例提供参数“brief”或“full”,也不会显示任何内容,并且调用 ax.get_le
根据 Shanes 优秀 solution另一个问题,我现在意识到我不知道该怎么做。 我最初的方法是使用融化数据(再次感谢 shane): dm1 <- melt(d[,c("Type","I.alt
我有一个多索引数据框,两个索引是 Sample 和 Lithology Sample 20EC-P 20EC-8 20EC-10-1 ... 20EC-43
我有一个关于 ggplot2 中的图例的问题。我设法在同一张图中绘制了三条线,并想添加使用三种颜色的图例。这是使用的代码 library(ggplot2) ## edit from original
我如何使用 seaborn 中的 lineplot 绘图功能来创建点之间没有连接线的绘图。我知道该函数称为 lineplot,但它具有合并所有具有相同 x 值的数据点并绘制单个均值和置信区间的有用功能
我如何使用 seaborn 中的 lineplot 绘图功能来创建点之间没有连接线的绘图。我知道该函数称为 lineplot,但它具有合并所有具有相同 x 值的数据点并绘制单个均值和置信区间的有用功能
我昨天发布了类似的内容,但什么也没得到。我今天花了几个小时解决问题,但没有取得任何进展。 我正在使用处理(语言)并尝试实现一种在两点之间绘制一条线的方法。 (我不想使用库的 line() 方法。) 我
我有一个如下所示的数据框 df: ind group people value value_50 1 1 5 100 1 1 2 2 90
我正在使用 seaborn.lineplot()创建一个像这样的线图(一条代表平均值的线,被一个代表标准的带包围): sns.lineplot(x="trial", y="rvalues", hue=
我有 jqplot 线图,其中 y 轴作为金额,x 轴作为日期。我需要详细说明将鼠标悬停在图表线上时显示的金额。如果有人知道请重播。谢谢.... 最佳答案 您尝试过荧光笔插件吗? http://www
我已经实现了折线图,并且运行良好。但对于某些值,该线不可见或被切断。我附上了截图。对于诸如 [Entry, x: 0.0 y: 0.0, Entry, x: 1.0 y: 0.0, Entry, x:
我正在尝试改编动画线图示例,来自:http://bl.ocks.org/benjchristensen/1148374 function draw(id, width, height, u
我是一名优秀的程序员,十分优秀!