gpt4 book ai didi

r - 连接点

转载 作者:行者123 更新时间:2023-12-04 09:10:24 26 4
gpt4 key购买 nike

我有以下情节

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(),但生成了一个错误

最佳答案

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

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

关于r - 连接点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15043956/

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