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
Error in eval(expr, envir, enclos) : object 'input' not found
First, in your ggplot call, you should have y = input$selecty
to 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
Ggplot2 Time Series Plotting: How to Omit Periods When There Is No Data Points
Subsetting a Data.Table by Range Making Use of Binary Search
How to Convert by the Minute Data to Hourly Average Data
Reshape Long Structured Data.Table into a Wide Structure Using Data.Table Functionality
Plot Only a Select Few Facets in Facet_Grid
More Efficient Strategy for Which() or Match()
Reproduce a 'The Economist' Chart with Dual Axis
Retrieve Census Tract from Coordinates
Porting Set Operations from R's Data Frames to Data Tables: How to Identify Duplicated Rows
Making a Zip Code Choropleth in R Using Ggplot2 and Ggmap
Scale_Y_Log10() and Coord_Trans(Ytrans = 'Log10') Lead to Different Results
Create Multilines from Points, Grouped by Id with Sf Package
Add Missing Xts/Zoo Data with Linear Interpolation in R
Rcpp Function Calling Another Rcpp Function
How to Ddply() Without Sorting
How to Make Scatterplot Points Open a Hyperlink Using Ggplotly - R