I am new to R/ggplot2 and am trying to create a line graph of counts (or percentages, it doesn't matter) for responses to 6 stimuli in ggplot in R. The stimuli should go across the x-axis, and the count on the y-axis. One line will represent the number of participants who responded with a preposition, and the other line will represent the number of participants who responded with a number.
I believe that ggplot with geom_line() requires an x and y (where y is the count or percentage).
Should I create a new data frame with count so that I can use ggplot? And then, a subquestion would be how do I count responses based on the stimulus data (so, how do I count response based on another column in the data frame, or how many preposition responses for stimulus 1, how many number responses for stimulus 1, how many preposition responses for stimulus 2, etc. Maybe with some kind of if statement?)?
or
Is there a way to automatically produce these counts in ggplot?
Of course, it's entirely possible that I'm going about this the wrong way entirely.
I've tried to search this, but cannot find anything. Thank you so much.
..count..variable.ggplot, this will also have the advantage of automating the counting, as the default behavior forgeom_bar()is to usestat="bin"(which counts the number of cases in each group) for the y-axis.stat = "bin"ingeom_lineif you want ggplot2 to count up the number per group for you. Lots of info about aggregating data by group on SO - see here and here for a start.