# Plotting grafic result

I am learning how to plot data. I am trying to obtain this grafic result on my dataset. The thing is, I can't do it. The cool plot is from a kaggle's kernel, which code is:

ggplot(cocoa,aes(x=pct, y=rating)) +geom_point(aes(colour=factor(location))) +
theme( legend.position="bottom",legend.key.width=unit(0.2,"cm"),legend.key.height=unit(0.2,"cm")) +
xlab("Cocoa Percent(%) ") + ylab("Chocolate Bar Rating") +
ggtitle("Scattor plot of Cocoa Percent vs Chocolate Bar Rating")


When I try to install "ggplot" on RStudio, it says Error in install.packages : object"ggplot" not found. So I tryied copying the text in plot() function. Obviously, it gives me errors on the arguments. The only thing I managed to do is this:

plot(data=chocolate, Rating~CocoaPerc, xlab="Rating", ylab="Cocoa Percentage", col="brown",
main="Valutazione e Percentuale di cacao")


Can anybody help me achieving the cool result? Or can you advise me any other "tricks" or guides about data plotting and grafic study of datasets? Thanks

You probably did:

install.packages(ggplot)


This is a common mistake: when installing a package you need quotes, otherwise R interprets the name of the package as a string and since the string isn't defined you get an "object not found" error. The correct version is:

install.packages("ggplot")


(with single or double quotes, it doesn't matter)

Note: I would normally use the ggplot2 package, but maybe ggplot redirects to the same package:

install.packages("ggplot2")

• Hi! I did as you wrote, using quotes. It gave me this error: Warning in install.packages : package ‘ggplot’ is not available (for R version 3.6.3) – user96624 May 23 at 14:47
• As I said, try ggplot2, probably the original version is obsolete. – Erwan May 23 at 16:37
• ggplot2 needs different arguments, right? Do you know a good guide about how to use it (besides official documentation)? thanks – user96624 May 23 at 16:42
• afaik ggplot2 is the "new" version of ggplot, it contains mostly the same functions with the same arguments. the main function to call is still "ggplot", try it with your data. The two reference books are mentioned here: had.co.nz/ggplot2, but there are countless tutorials online as well. Imho the graphic you're trying to do is a bit complex for a beginner, you could start with more simple things to grasp the idea. – Erwan May 23 at 17:07
• Thank you very much for your help! – user96624 May 23 at 17:19