R 如何基于ggplot中的列值连接点。(包括示例代码)
如何基于特定列的值,使用ggplot连接绘图上的特定点?我使用基本绘图系统解决了这个问题,但我想知道如何使用ggplot完成这个任务 使用基本打印系统完成此任务的代码:R 如何基于ggplot中的列值连接点。(包括示例代码),r,ggplot2,R,Ggplot2,如何基于特定列的值,使用ggplot连接绘图上的特定点?我使用基本绘图系统解决了这个问题,但我想知道如何使用ggplot完成这个任务 使用基本打印系统完成此任务的代码: #Defining the dataset states <- letters[1:10] set.seed(12345) profit.2010 <- runif(10, 1000, 2000) profit.2011 <- runif(10, 1000, 2000) data <- data.fram
#Defining the dataset
states <- letters[1:10]
set.seed(12345)
profit.2010 <- runif(10, 1000, 2000)
profit.2011 <- runif(10, 1000, 2000)
data <- data.frame(states, profit.2010, profit.2011)
#Making a plot using base plotting system
par(mfrow = c(1, 1))
with(data, plot(rep(1, 10), data[, 2], xlim = c(.5, 2.5)))
with(data, points(rep(2, 10), data[, 3]))
segments(rep(1, 10), data[, 2], rep(2, 10), data[, 3])
#定义数据集
状态如果需要线,请添加一条geom_线
,并设置组=
,以便它知道要连接的点
ggplot(dat, aes(year, profit)) +
geom_text(aes(label = states)) +
geom_line(aes(group = states))
谢谢你的解决方案!
ggplot(dat, aes(year, profit)) +
geom_text(aes(label = states)) +
geom_line(aes(group = states))