0

I am working on a shiny app that is supposed to enable the user to load data from an excel file and to create some graphs based on this data. To do this I use read.xlsx and ggplot. The user can select the x variable input$x and y variable input$y from a list. This list is created based on the column names of the data set. Based on the input a graph is created:

ggplot() +  geom_point(data=mydata, aes_string(x=input$x, y=input$y)

However, when some of the columns of my example dataset are chosen, I get an error. For instance, when i select the y variable to be equal to the AB (m/s), I get the following error:

Error: could not find function "AB"

The ggplot somehow does not recognize the special characters and only takes the first part of the column name. Is there a way to solve this?

1
  • 1
    The issue is that the variables contain space. If you cannot rename the columns (e.g. replace spaces with _) you can try with `. `x` may work. Commented May 29, 2020 at 10:10

1 Answer 1

1

Thank you for the nice suggestion fra. Eventually i have solved it like this:

x<-paste0("`",input$x,"`")
y<-paste0("`",input$y,"`")
ggplot() +  geom_point(data=mydata, aes_string(x=x, y=y)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.