我有这个数据框:
structure(list(month_num = 1:24, founded_month = c(4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 1L, 2L, 3L), founded_year = c(2008L, 2008L, 2008L,
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2009L, 2009L, 2009L,
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L,
2010L, 2010L, 2010L), count = c(270L, 222L, 256L, 250L, 277L,
268L, 246L, 214L, 167L, 408L, 201L, 225L, 203L, 220L, 230L, 225L,
177L, 207L, 166L, 135L, 116L, 122L, …Run Code Online (Sandbox Code Playgroud) 我想知道如何使它在下面的示例数据集中的x和y在水平轴上的每个框架元素的垂直轴上绘制.我如何使用ggplot2执行此操作?
x,y =变量,frame = YYYYMM
示例数据:
df <- structure(list(x = c(0.000892333625290767, 0.0161153931761482,
0.0188150880795816, 0.0268699106638318, 0.018657330651898, 0.0101065034206662,
0.00154410447630379), y = c(1.35172948829027, 0.59654026447333,
0.685835030118683, 0.741545898152761, 1.09653338596292, 0.119448208345102,
0.104092642854814), frame = c(200912, 201001, 201002, 201003,
201004, 201005, 201006)), .Names = c("x", "y", "frame"), row.names = c("1",
"2", "3", "4", "5", "6", "7"), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
我已经能够在一行中绘制一个,但似乎它没有将我的框架识别为分类(不是它,我也不知道如何将其更改为此类).
p <- ggplot(df, aes(x=frame, y=x))
p + geom_line()
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以使用R中的ggplot创建包含多个系列图的图形的图例框.基本上,这就是我正在做的事情.
x <- c(1,2,3,4)
y <- c(1.1,1.2,1.3,1.4)
y2 <- c(2.1,2.2,2.3,2.4)
x3 <- c(4,5,6,7)
y3 <- c(3.1,3.2,3.3,3.2)
p1 <- data.frame(x=x,y=y)
p2 <- data.frame(x=x,y=y2)
p3 <- data.frame(x=x3,y=y3)
ggplot(p1, aes(x,y)) + geom_point(color="blue") + geom_point(data=p2, color="red") + geom_point(data=p3,color="yellow")
Run Code Online (Sandbox Code Playgroud)
上面的命令将以三种不同的颜色绘制所有三个数据集p1,p2和p3的图形.我知道我还没有指定每个数据集的名称,但我如何创建标识不同数据集的图例?换句话说,我只想要一个传说,说明所有蓝点都是P1,所有红点都是P2,所有黄点都是P3.
我是R的初学者,我遇到了问题,需要你的帮助.
我有一个包含这样的数据的文本文件:
A C G class phylum order
-0.000187 -0.219166 1.693306 Chordata Monotremata Mammalia
0.015664 -0.264506 1.482692 Chordata Batidoidimorpha Chondrichthyes
-0.404323 0.219374 2.230190 Platyhelminthes Cyclophyllidea Cestoda
Run Code Online (Sandbox Code Playgroud)
但当然它有很多行.我想以这样的方式绘制这些数据,即所有类都绘制在x轴上,每一个都将A,C和G值绘制为geom_point,并且这些点使用具有特定线的线连接颜色取决于A,C或G.我设法通过使用plot和par函数来实现这一点,但现在我想使用ggplot库来完成它.
提前致谢.