You can use the aes_string
in stead of aes
to pass string in stead of using objects, i.e.:
myplot = function(df, x_string, y_string) {
ggplot(df, aes_string(x = x_string, y = y_string)) + geom_point()
}
myplot(df, "A", "B")
myplot(df, "B", "A")
More Related Contents:
- Color one point and add an annotation in ggplot2?
- How to convert a list consisting of vector of different lengths to a usable data frame in R?
- Filtering a data frame on a vector [duplicate]
- How to replace NA values in a table for selected columns
- How to set multiple legends / scales for the same aesthetic in ggplot2?
- Addressing x and y in aes by variable number
- customize ggplot2 axis labels with different colors
- ggplot2: Divide Legend into Two Columns, Each with Its Own Title
- Split data.frame by value
- Convert data.frame column to a vector?
- Add new row to dataframe, at specific row-index, not appended?
- ggplot2 multiple sub groups of a bar chart
- Use different center than the prime meridian in plotting a world map
- Display custom image as geom_point [duplicate]
- multiple graphs in one canvas using ggplot2
- Save plot with a given aspect ratio
- Splitting a data.frame by a variable [duplicate]
- Getting a stacked area plot in R
- geom_text how to position the text on bar as I want?
- Unlist a data frame by rows, not columns
- Force ggplot legend to show all categories when no values are present [duplicate]
- modifying ggplot objects after creation
- Greek letters, symbols, and line breaks inside a ggplot legend label
- DT[!(x == .)] and DT[x != .] treat NA in x inconsistently
- how do you order Months in ggplot
- The perils of aligning plots in ggplot
- How to create a new variable in a data.frame based on a condition?
- How do I loop through column names and make a ggplot scatteplot for each one
- Interpolating timeseries
- Make a rectangular legend, with rows and columns labeled, in grid