R 在ggplot2中合并来自不同数据集的条形图和stat_smooth()线

R 在ggplot2中合并来自不同数据集的条形图和stat_smooth()线,r,ggplot2,bar-chart,R,Ggplot2,Bar Chart,我试图将一个数据集的stat\u smooth()行覆盖在另一个数据集的条形图上。两个csv文件都来自同一个数据集,但我必须为条形图创建一个新的数据集,因为我必须添加一些在大csv中没有意义的列(包括错误条)。所以,我有用于条形图的代码,以及使用stat_smooth生成的线的代码,但是我不知道如何组合它们。我只想要一个在条上有线的图表。以下是条形图的代码: `e <- read.csv("Retro Complex.csv", header=T, sep="

我试图将一个数据集的
stat\u smooth()
行覆盖在另一个数据集的条形图上。两个csv文件都来自同一个数据集,但我必须为条形图创建一个新的数据集,因为我必须添加一些在大csv中没有意义的列(包括错误条)。所以,我有用于条形图的代码,以及使用stat_smooth生成的线的代码,但是我不知道如何组合它们。我只想要一个在条上有线的图表。以下是条形图的代码:

`e <- read.csv("Retro Complex.csv", header=T, sep=",")
 e <- subset(e, Accuracy != 0)
limits <- aes(ymax = Confidence + SE, ymin = Confidence - SE)
e$Complexity <- factor(e$Complexity)
p <- ggplot(e, aes(e$Complexity, Confidence))
p +
  geom_bar(position = "dodge", stat = "identity") +
  geom_errorbar(limits, position = "dodge", width = 0.25) +
  coord_cartesian(ylim=c(0,1)) +
  scale_y_continuous(labels = percent) +
  ggtitle("Retro")`
structure(list(Complexity = structure(1:5, .Label = c("1", "2", 
"3", "4", "5"), class = "factor"), Accuracy = c(1L, 1L, 1L, 1L, 
1L), Risk = c(0.69297164, 0.695793434, 0.695891571, 0.746606335, 
0.748717949), SE = c(0.003621776, 0.004254081, 0.00669456, 0.008114764, 
0.021963804), Proportion = c(0.823475656, 0.809299751, 0.863727821, 
0.94724695, 0.882352941), SEAcc = c(0.002716612, 0.003267882, 
0.004639995, 0.004059001, 0.015325003)), .Names = c("Complexity", 
"Accuracy", "Confidence", "SE", "Proportion", "SEAcc"), row.names = c(1L, 
3L, 5L, 7L, 9L), class = "data.frame")
以下是它们的外观:

Stat\u smooth()
行:

条形图:

样本数据 对于条形图:

`e <- read.csv("Retro Complex.csv", header=T, sep=",")
 e <- subset(e, Accuracy != 0)
limits <- aes(ymax = Confidence + SE, ymin = Confidence - SE)
e$Complexity <- factor(e$Complexity)
p <- ggplot(e, aes(e$Complexity, Confidence))
p +
  geom_bar(position = "dodge", stat = "identity") +
  geom_errorbar(limits, position = "dodge", width = 0.25) +
  coord_cartesian(ylim=c(0,1)) +
  scale_y_continuous(labels = percent) +
  ggtitle("Retro")`
structure(list(Complexity = structure(1:5, .Label = c("1", "2", 
"3", "4", "5"), class = "factor"), Accuracy = c(1L, 1L, 1L, 1L, 
1L), Risk = c(0.69297164, 0.695793434, 0.695891571, 0.746606335, 
0.748717949), SE = c(0.003621776, 0.004254081, 0.00669456, 0.008114764, 
0.021963804), Proportion = c(0.823475656, 0.809299751, 0.863727821, 
0.94724695, 0.882352941), SEAcc = c(0.002716612, 0.003267882, 
0.004639995, 0.004059001, 0.015325003)), .Names = c("Complexity", 
"Accuracy", "Confidence", "SE", "Proportion", "SEAcc"), row.names = c(1L, 
3L, 5L, 7L, 9L), class = "data.frame")
对于线路:

structure(list(risk = c(0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), acc = c(0L, 1L, 1L, 1L, 
0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 
    Uniqueness = c(0.405166959, 0.407414244, 0.285123931, 0.248994487, 
    0.259019778, 0.334552913, 0.300580793, 0.354632526, 0.309841996, 
    0.331460876, 0.289981111, 0.362405881, 0.37389863, 0.253672193, 
    0.342903451, 0.294459829, 0.387447291, 0.519657612, 0.278964406
    ), Average.Similarity = c(0.406700667, 0.409547355, 0.275663862, 
    0.240909144, 0.251796956, 0.31827466, 0.240574971, 0.349093002, 
    0.34253811, 0.348084627, 0.290495997, 0.318312198, 0.404143605, 
    0.290789337, 0.293259599, 0.320214236, 0.382449298, 0.506295194, 
    0.335167223), Complexity.Sample = c(8521L, 11407L, 3963L, 
    2536L, 2327L, 3724L, 4005L, 5845L, 5770L, 5246L, 3629L, 3994L, 
    4285L, 1503L, 8222L, 3683L, 5639L, 10288L, 3076L)), .Names = c("risk", 
"acc", "Uniqueness", "Average.Similarity", "Complexity.Sample"
), class = "data.frame", row.names = c(NA, -19L))

所以,是的,如果你们中有人知道如何将这些组合成一个情节,请让我知道

你不能从
p+stat\u smooth(aes(x=Complexity.Sample,y=risk),data=retroacc,method=“glm”,method.args=list(family=“binomial”),se=FALSE)中得到你想要的吗?
?欢迎来到堆栈溢出!如果您在提问时提供一些示例数据,这将非常有用。这样一来,人们就有了一个最低限度的工作示例。@IanWesley,我不知道如何提供数据,而不只是从excel中复制和粘贴数据。我看过其他问题的示例,但找不到他们是如何做到的。我该怎么做?@Pdubbs,我已经试过了,但它回吐出“eval(expr,envir,enclose)中的错误:找不到对象‘Confidence’”。我试过几种不同的形式,而且nada@GB1
dput(您的_对象)
命令将输出一个命令以在R中创建数据。听起来
e
相当大,所以您可能只想为我们输出一个子集。(确保您的子集生成相同的错误)