如何使用ggplot2绘制累积频率线图?

问题描述

如果这个问题是不言自明的,请原谅我,但我仍在努力掌握 R 的更多功能。

我目前正在尝试使用 R 用我在 excel 中绘制的线条重新绘制累积频率。

Here is a picture of the graph I am trying to recreate

我认为我的很多问题都来自有很多没有数据的单元格,因为我不断收到警告:

警告信息:
1:删除了包含缺失值的 81 行(geom_path)。
2:删除了包含缺失值的 81 行(geom_path)。
3: 删除了 81 行包含缺失值 (geom_path)。

这是因为每列代表一个记录频率,只发生了 21 天,每个记录周期之间有 20 天的休息时间。

My data table

我曾尝试使用 import Feather from 'react-native-vector-icons/Feather'; const App: () => React$Node = () => { return ( <Feather name="chevron-left" color={'#2F80ED'} size={30} /> ); }; export default App; geom_ steps(),但最终得到了这些:

Graphic produced using geom_step

graphic produced with geom_point

当我使用 geom_points() 函数时,轴被创建但没有绘制任何内容。

Graphic produced using geom_line

x 轴上的日期看起来也很糟糕,我尝试使用代码 geom_line() 来旋转标签,但它看起来仍然很糟糕,我不确定它是否只是多个日期。

这是我一直在尝试为各种 geom 函数工作的代码:

+ theme(axis.text.x = element_text(angle = 90))

我希望这一切都有意义,并提前感谢大家提供的任何帮助!

我使用 ggplot() + geom_point(aes(x = Date,y = d2s1,group = 1),data = cf) + geom_point(aes(x = Date,y = d20s1,y = d10s1,data = cf) + theme(axis.text.x = element_text(angle = 90)) ggplot() + geom_step(aes(x = Date,data = cf) + geom_step(aes(x = Date,data = cf) + theme(axis.text.x = element_text(angle = 90)) ggplot() + geom_line(aes(x = Date,data = cf) + geom_line(aes(x = Date,data = cf) + theme(axis.text.x = element_text(angle = 90)) 读入数据。

我在下面附上了 read.csv("cf.csv") 的输出。

dput(cf)

解决方法

函数 geom_step() 有一个参数 na.rm 来删除 NA 值,默认情况下是 FALSE。将此更改为 TRUE 应该会给你你想要的图。或者,您可以将 NA 数据更改为零以获得相同的效果。

拥挤的 x 轴是将数据存储为因子而不是日期时会发生的典型情况。这将与您读取数据的方式有关,而您尚未显示这些数据。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...