相关疑难解决方法(0)

美学必须是长度为1或与dataProblems相同的长度

我想制作一个图,其中X值作为测量的子集,Y值作为测量数据的另一个子集.

在下面的例子中,我有4个产品p1,p2,p3和p4.每个都根据他们的歪斜,颜色和版本定价.我想创建一个多面图,描绘P3产品(Y轴)与P1产品(X轴).

我的下面的尝试失败了,出现以下错误:

错误:美学必须是长度为1或与dataProblems相同的长度:子集(price,product =="p1"),子集(price,product =="p3")

library(ggplot2)
product=c("p1","p1","p1","p1","p1","p1","p1","p1","p2","p2","p2","p2","p2","p2","p2","p2","p3","p3","p3","p3","p3","p3","p3","p3","p4","p4","p4","p4","p4","p4","p4","p4")
skew=c("b","b","b","b","a","a","a","a","b","b","b","b","a","a","a","a","b","b","b","b","a","a","a","a","b","b","b","b","a","a","a","a")
version=c(0.1,0.1,0.2,0.2,0.1,0.1,0.2,0.2,0.1,0.1,0.2,0.2,0.1,0.1,0.2,0.2,0.1,0.1,0.2,0.2,0.1,0.1,0.2,0.2,0.1,0.1,0.2,0.2,0.1,0.1,0.2,0.2)
color=c("C1","C2","C1","C2","C1","C2","C1","C2","C1","C2","C1","C2","C1","C2","C1","C2","C1","C2","C1","C2","C1","C2","C1","C2","C1","C2","C1","C2","C1","C2","C1","C2")
price=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32)
df = data.frame(product, skew, version, color, price)
# First plot all the data
p1 <- ggplot(df, aes(x=price, y=price, colour=factor(skew))) + geom_point(size=2, shape=19)
p1 <- p1 + facet_grid(version ~ color)
p1 # This gavea very good plot. So far so good
# Now plot P3 vs P1
p1 <- ggplot(df, aes(x=subset(price, product=='p1'), y=subset(price, product=='p3'), colour=factor(skew))) + geom_point(size=2, shape=19)
p1
# failed with: Error: Aesthetics must either be length one, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 aesthetics

31
推荐指数
3
解决办法
17万
查看次数

r - 用户通过闪亮输入值到数据帧

我正在构建一个应用程序,允许用户从中传递值selectizeInputcheckboxInput形成数据帧.我搜索了一段时间,发现这些来源与我的期望相似:

  1. handsontable

它来自这里:https://github.com/jrowen/rhandsontable.我非常类似于这个例子:

shiny::runGitHub("jrowen/rhandsontable",
                 subdir = "inst/examples/rhandsontable_portfolio")
Run Code Online (Sandbox Code Playgroud)

但我想使用闪亮的小部件将值传递给数据帧.它应该能够添加/删除行,如下例所示:

  1. shinyIncubator

代码在这里:

library("shiny")
library('devtools')
install_github('shiny-incubator', 'rstudio')
library("shinyIncubator")

# initialize data with colnames
df <- data.frame(matrix(c("0","0"), 1, 2))
colnames(df) <- c("Input1", "Input2")
    server = shinyServer(
      function(input, output) {
        # table of outputs
        output$table.output <- renderTable(
          { res <- matrix(apply(input$data,1,prod))
          res <- do.call(cbind, list(input$data, res))
          colnames(res) <- c("Input 1","Input 2","Product")
          res
          }
          , include.rownames = FALSE
          , include.colnames = TRUE
          , align = "cccc"
          , digits …
Run Code Online (Sandbox Code Playgroud)

r shiny

1
推荐指数
1
解决办法
1538
查看次数

标签 统计

r ×2

aesthetics ×1

ggplot2 ×1

shiny ×1