gpt4 book ai didi

r - 2 列数据的 2 种颜色的简单点图

转载 作者:行者123 更新时间:2023-12-02 01:26:43 25 4
gpt4 key购买 nike

我使用 df = as.data.frame(read.table("file.txt"))

从文本文件中将以下数据导入 R
    AED round2 round3
1 0.00 0.020 0.022
2 0.02 0.041 0.045
3 0.04 0.066 0.073
4 0.06 0.094 0.103
5 0.08 0.120 0.132
6 0.10 0.146 0.160
7 0.12 0.171 0.189
8 0.14 0.195 0.215
9 0.16 0.218 0.241
10 0.18 0.240 0.265

现在我想在 y 轴上绘制 round2 的值与 x 轴上的 AED 的值的简单点图,并在同一图形中绘制 round3 的值的第二个图,颜色不同,刻度为 0.10 间隔.

到目前为止,我想到的最佳解决方案是 qplot(data=df, AED, round2, color="Round2")

但我需要一些帮助,如何获得第二个绘图以及如何将轴上的间距从 0.25 更改为 0.10

我在这里阅读教程 http://www.cookbook-r.com/Graphs/Axes_%28ggplot2%29/但他们使用不同的数据布局,为每一行明确指定组,而不是通过简单的标题。

那么我怎样才能让它为每一列绘制 1 个图呢? (在一张图中)

最佳答案

试试这个:

library(ggplot2)
library(tidyr)

# wide to long format
plotDat <- gather(df, Group, myValue, -1)

# plot
ggplot(plotDat, aes(AED, myValue, col = Group)) +
geom_point() +
#fix breaks on axis
scale_x_continuous(breaks = seq(0, 1, 0.1)) +
scale_y_continuous(breaks = seq(0, 1, 0.1))

enter image description here

关于r - 2 列数据的 2 种颜色的简单点图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36745679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com