How do you create a stacked bar graph in R?

So, I’ve been learning R for less than two weeks, and I’m trying to make a stacked bar graph. It is…more or less not working out. I found this page, which looks like it has the information I need, but I am just too much of a blockhead to understand what the code means and what exactly it’s asking for.

Could anyone help me understand this?

counts <- table(mtcars$vs, mtcars$gear) This part defines a table (mtcars) as the source of your data. The variables are vs and gear.

barplot(counts, This part specifies a barplot with the data from the table controlling the height of the bars.

main=“Car Distribution by Gears and VS”, This part defines the main title.

xlab=“Number of Gears”, This part labels your X-axis.

col=c(“darkblue”,“red”), This part colors the stack, using a dataframe.

**legend = rownames(counts)) ** And this part creates a legend using the names of the rows in the table.

Read the rest of that website might give you a bit more insight.