Hi, I'm trying to plot a categorical variable, the code works if i plot all categories and separate them by color. this is fine but it is not what I want. Instead, i want to isolate the categories such that the plot only shows points of a single category. i have set my aesthetics individualy because i want to have various plots from the same data on a single canvas so that i can do comparison. the code gives me an error as shown below.
ggplot(data) + geom_point(aes(x= A[gender == "male"],y = B [gender == "male"])) +
geom_smooth(aes (x= A[gender == "female"],y = B [gender == "female"]), method= 'lm' , se = F)
Error: Must subset columns with a valid subscript vector.
i Logical subscripts must match the size of the indexed input.
x Input has size 12 but subscript gender == "male" has size 1296.
Run rlang::last_error() to see where the error occurred
Hello and Welcome to the forum, I hope you will find us friendly and helpful.
To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
say for example i'm using the iris data-set as you illustrated above. i want to plot the sepal.width vs sepal.length with respect to the species column. But instead of color coding each species on the plot, i want the plot to display only the data from the setosa species alone
for me to plot it by color it would be
ggplot(iris, aes(x=sepal.length, y= sepal.width), col= species )+ geom_point()
but in my case i want to draw a specific specie from the species column. what i have tried was:
Error: Must subset columns with a valid subscript vector.
i Logical subscripts must match the size of the indexed input.
x Input has size 12 but subscript gender == "male" has size 1296.
Run rlang::last_error() to see where the error occurred
in my case,"gender" and "male" represents the variable and subset category similar to"species" and "setosa" in the iris dataframe
Hi, you can set an entire plot, or even just one geom to use a subset of the data, but you would do it like this, with a formula and on the data portion, reserve the aes for only assigning variables to roles.