连接点 [英] connecting points

查看:61
本文介绍了连接点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情节

require(ggplot2)

dtf <- structure(list(Variance = c(5.213, 1.377, 0.858, 0.613, 0.412, 0.229, 0.139, 0.094, 0.064), Component = structure(1:9, .Label = c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9"), class = "factor")), .Names = c("Variance", "Component"), row.names = c(NA, -9L), class = "data.frame")

ggplot(dtf, aes(x = Component, y = Variance)) +
geom_point()

我只想将点与直线连接起来.我尝试了+geom_line(),但是生成了一个错误

I would simply like to connect the dots with straight lines. I tried +geom_line() but that generated an error

推荐答案

您的x值是离散的(因数),并且geom_line()每个唯一的x值都被视为单独的组,并尝试仅在该组内连接点.在aes()中设置group=1可确保将所有值都视为一组.

Your x values are discrete (factor) and geom_line() each unique x value perceive as separate group and tries to connect points only inside this group. Setting group=1 in aes() ensures that all values are treated as one group.

ggplot(dtf, aes(x = Component, y = Variance,group=1)) +
  geom_point()+geom_line()

这篇关于连接点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆