我正试图在一个闪亮的app中用一个图形绘制两个具有对数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”不是图形参数
我读过的大部分文档都说log="x"
就是这样做的。其他人说这是logx=T
。后者不会出现错误,但也不会使x轴呈对数。我一直在敲打这个应用程序很多很多小时,任何帮助都会受到赞赏!
答案 0 :(得分:0)
当您指定绘图(...,log =&#39; x&#39;)时,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
答案 1 :(得分:0)
问题是您在添加的第二个绘图命令中再次指定了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)