【问题标题】:"log" is not a graphical parameter' error when using plot()使用 plot() 时“log”不是图形参数错误
【发布时间】:2015-08-08 06:23:11
【问题描述】:

我正在尝试在一个闪亮的应用程序的一个图中绘制两个带有对数 x 轴的直方图。这是引发错误的代码:

allGeneData <- read.csv('data/CoRN_data1.csv')

shinyServer(function(input, output) {

  igsAll <- allGeneData[allGeneData$Gene=="IGS",]
  igsClean <- igsAll[!is.na(igsAll$copies_indiv_fit_avg),]
  igsClean$copies_indiv_fit_avg <- igsClean$copies_indiv_fit_avg + 1
  xmax <- max(igsClean$copies_indiv_fit_avg)*1.1
  ylimits <- seq(0,10)

  varList <- levels(allGeneData$variety)

  selectedVar <- reactive({
    s <- igsClean[igsClean$variety==input$varietySelect,]
    sNumbs <- s$copies_indiv_fit_avg
    sHisto <- hist(sNumbs)
    return(sHisto)
  })
  remainder <- reactive({
    r <- igsClean[igsClean$variety!=input$varietySelect,]
    rNumbs <- r$copies_indiv_fit_avg
    rHisto <- hist(rNumbs)
    return(rHisto)
  })

  output$ggplotHisto2 <- renderPlot({
    plot(selectedVar(), col=rgb(0,1,1,.25), xlim=c(1,xmax), ylim=c(0,12), log="x")
    plot(remainder(), col=rgb(1,1,0,.25), xlim=c(1,xmax), ylim=c(0,12),add=T)
  })
})

这是错误:

运行中的警告(timeoutMs):“日志”不是图形参数

我阅读的大部分文档都说log="x" 是如何完成的。其他人说它是logx=T。后者不会产生错误,但也不会使 x 轴对数。我已经在这个应用程序上敲了很多很多小时,任何帮助都将不胜感激!

【问题讨论】:

  • 我在使用title函数时遇到了同样的错误,你的问题解决了吗?
  • 您需要说明是哪个函数调用产生了错误。它真的是由第一次调用 plot 引发的,还是由调用 plot 中的一个 hist 调用引发的?此外,尝试将该代码最小化为产生相同错误的更小代码。大概甚至不需要“余数”函数和绘图,也没有使用 varList。去掉所有不需要证明错误的计算和绘图参数。

标签: r plot


【解决方案1】:

当您指定 plot(..., log = 'x') 时,R 在(自然)对数刻度上绘制 x 轴,但您在 x 轴上看到的值是未记录的值。

要查看上述陈述如何正确的示例,请考虑以下示例:

y = rnorm(3) #Generate 3 random numbers
x = c(2.7,2.7^2,2.7^3) #Approximately equal to 1, 2, 3 on log scale
plot(y~log(x), bg = 'blue', pch =21) #Plot by directly taking log x
par(new=T) #Used to overlay plot
plot(y~x, col ='red', log='x', xaxt = 'n', pch = 2, xlab = "") #Another way to plot where x is on log scale.          
#Remove x axis labels. 

#The two plots are identical

【讨论】:

    【解决方案2】:

    问题是您在添加的第二个绘图命令中再次指定了log = "x"

    以下触发警告: plot(1:100, log = "x") plot((1:100)^2, log = "x", add = TRUE)

    而以下没有,但给出了相同的情节: plot(1:100, log = "x") plot((1:100)^2, add = TRUE)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多