Hi, I am a beginner who just started learning RStudio.
I am trying to plot my GPS marketshare data set using the command plot(gps$marketshare, gps$company) and I get the error message as shown in my screenshot:
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:
Indeed, plot() makes scatterplots by default, which won't work with characters. It need to be told explicitly that it's a categorical variable and not random characters. You do that by making Company a factor:
But there are also 2 other possibilities for this kind of data, that will automatically guess that Company is supposed to be a factor:
2nd method: use barplot
Barplots are commonly used for this kind of data, and make more sense if you have a single point per condition. The barplot() function automatically guesses that the x axis is supposed to be a factor, since it's the standard use case:
barplot(MarketShare ~ Company, data = gps)
3rd way: use ggplot2
The two previous functions are part of base R, but the ggplot2 package offers many additional possibilities with a consistent syntax, and might be worth learning about. It's part of the tidyverse, so automatically available if you already did library(tidyverse). It will also guess automatically that Company is a categorical variable.
library(ggplot2) # or library(tidyverse)
# display as points
ggplot(gps) +
geom_point(aes(x=Company, y=MarketShare))
# display as bars
ggplot(gps) +
geom_col(aes(x=Company, y=MarketShare))