Geom_Rect Failure: Error in Eval(Expr, Envir, Enclos):Object 'Variable' Not Found

geom_rect failure: Error in eval(expr, envir, enclos) : object 'variable' not found

In the first ggplot call you map the colour to 'variable'. This mapping is still present in the geom_rect call, but no variable named 'variable' exists in 'trips'. I would suggest to unmap colour using:

p2 <- p + geom_rect(aes(NULL, NULL, xmin=From, xmax=To, colour=NULL),
ymin=yrng[1], ymax=yrng[2],
data=trips)

(Haven't tried it, but I guess it should work).

Error in eval(expr, envir, enclos) : object 'Tribe' not found

You want the colour of your points to vary by the variable state, so it should be inside the aes:

 geom_point(aes(colour = State))

Anything outside of the aes is constant, so, colour=red or size=2.

ggplot call inside a function: Error in eval(expr, envir, enclos) : object '...' not found

I had the same problem and found the answer here: Use of ggplot() within another function in R

As suggested there, adding environment parameter like below worked for me:

library(reshape2)
library(ggplot2)

compare <- function(list.a, list.b, selection)
{
df <- melt(as.data.frame(t(matrix(c( list.a[selection], list.b[selection]), nrow=2, byrow=TRUE))))
xaxis <- rep(c(1:length(selection)), 2)
# ggplot(df, aes(x=xaxis, y=value, colour=variable)) + geom_line() # fails
ggplot(df, aes(x=xaxis, y=value, colour=variable),environment=environment()) + geom_line() # works
}

compare(runif(100, 0, 1), runif(100, 0, 1), c(30:80))

ggplot2 Error in eval(expr, envir, enclos) : object not found

Somehow you've created an invalid data.frame. You've stored a matrix in the second column of cspdistbv; dim(cspdistbv) thinks it only has two columns and this interferes with proper naming and such. I'm not sure how you created it, but you can fix it with

cspdistbv  <- cbind.data.frame(lanem=cspdistbv[,1], cspdistbv[,2])

And then

cb1 <- ggplot() + geom_point(data = spdistbc, mapping = aes(x=speedmph, 
y = cprob, color = 'observed')) + facet_wrap(~Lane) + theme_bw()
cb2 <- cb1 + geom_point(data = cspdistbv, mapping = aes(x = speedmph,
y = prob, color = 'simulated-default')) + facet_wrap(~lanem)

should work

Sample Image

Error in eval(expr, envir, enclos) : object 'input' not found

First, in your ggplot call, you should have y = input$selectyto be consistent with your naming in ui.R.

Then, if I understood correctly, you should take a look at the aes_string function in ggplot because aes uses non-standard evaluation which allows you to specify variable names directly and not as characters. Here, input$yselect is passed as a character so you need to replace in server.R :

p <- ggplot(pdata(), aes(x = Time_Stamp, y = input$yselect)) + geom_point()

with

p <- ggplot(pdata(), aes_string(x = "Time_Stamp", y = input$selecty)) + geom_point()


Related Topics



Leave a reply



Submit