带有数据框列的ggplot

Pro*_*ion 4 plot r graph ggplot2

我完全迷失了使用ggplot.我尝试过各种解决方案,但都没有成功.使用下面的数字,我想创建一个折线图,其中三条线代表df $ c,df $ d和df $ e,x轴代表df $ a,y轴代表累积概率95 = 100%.

          a     b                    c                    d             e
1         0    18          0.047368421          0.036842105   0.005263158
2         1    20          0.047368421          0.036842105   0.010526316
13        2    26          0.052631579          0.031578947   0.026315789
20        3    35          0.084210526          0.036842105   0.031578947
22        4    41          0.068421053          0.052631579   0.047368421
24        5    88          0.131578947          0.068421053   0.131578947
26        7    90          0.131578947          0.068421053   0.136842105
27        8    93          0.126315789          0.068421053   0.147368421
28        9    96          0.126315789          0.073684211   0.152631579
3        10   115          0.105263158          0.078947368   0.210526316
4        11   116          0.105263158          0.084210526   0.210526316
5        12   120          0.094736842          0.084210526   0.226315789
6        13   128          0.105263158          0.073684211   0.247368421
7        14   129          0.100000000          0.073684211   0.252631579
8        15   154          0.031578947          0.042105263   0.368421053
9        16   155          0.031578947          0.036842105   0.373684211
10       17   158          0.036842105          0.036842105   0.378947368
11       18   161          0.036842105          0.031578947   0.389473684
12       19   163          0.026315789          0.031578947   0.400000000
14       20   169          0.026315789          0.021052632   0.421052632
15       21   171          0.015789474          0.021052632   0.431578947
16       22   174          0.010526316          0.021052632   0.442105263
17       24   176          0.010526316          0.021052632   0.447368421
18       25   186          0.005263158          0.005263158   0.484210526
19       26   187          0.005263158          0.000000000   0.489473684
21       35   188          0.005263158          0.005263158   0.489473684
23       40   189          0.005263158          0.000000000   0.494736842
25       60   190          0.000000000          0.000000000   0.500000000
Run Code Online (Sandbox Code Playgroud)

使用R基本编码我有点成功

plot(df$a, df$c, type="l",col="red")
lines(df$a, df$d, col="green")
lines(df$a, df$e, col="blue")
Run Code Online (Sandbox Code Playgroud)

Rom*_*rik 13

首先需要融合数据,以便有一列指定数据来自哪些变​​量(称之为variable),另一列指出实际值(称之为value).研究下面的示例,以充分了解您希望保持不变的原始data.frame中的变量会发生什么.

library(reshape2)
xymelt <- melt(xy, id.vars = "a")

library(ggplot2)
ggplot(xymelt, aes(x = a, y = value, color = variable)) +
  theme_bw() +
  geom_line()

ggplot(xymelt, aes(x = a, y = value)) +
  theme_bw() +
  geom_line() +
  facet_wrap(~ variable)
Run Code Online (Sandbox Code Playgroud)

此代码还从您的数据"d"中绘制列.您可以在熔化之前,熔化之后,在绘图之前将其移除...或绘制它.

在此输入图像描述