I am a R newbie. I am currently using Rstudio and trying to develop a program that graphs whatever the user gives it (assuming it is a csv file). My problem is, I do not know how to reference the columns in the data that the user is giving. Here is a portion of my code:
library(shiny)
library(datasets)
library(ggplot2)
X <- read.csv(file.choose())
print(qplot(data=X, **x=?????, y=?????**, main="la"))
For the qplot function (or ggplot2), I want to give an x and y value (columns in the csv). Normally you would just use the fileName$ColumnName
, but in this case, I don't know what's in the data the user is uploading (so I don't know the column names).
I've tried doing this, without success:
library(shiny)
library(datasets)
library(ggplot2)
X <- read.csv(file.choose())
headers <- names(X)
print(qplot(data=X, **x=X$headers[1], y=X$headers[2]**, main="la"))
Any ideas guys?
EDIT: I'd also like to be able to display the column name on the graph. Is there a way to do this?