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


1 Answer 1


You probably did:


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:


(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:

  • $\begingroup$ 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) $\endgroup$
    – user96624
    May 23, 2020 at 14:47
  • 1
    $\begingroup$ As I said, try ggplot2, probably the original version is obsolete. $\endgroup$
    – Erwan
    May 23, 2020 at 16:37
  • $\begingroup$ ggplot2 needs different arguments, right? Do you know a good guide about how to use it (besides official documentation)? thanks $\endgroup$
    – user96624
    May 23, 2020 at 16:42
  • 1
    $\begingroup$ 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. $\endgroup$
    – Erwan
    May 23, 2020 at 17:07
  • $\begingroup$ Thank you very much for your help! $\endgroup$
    – user96624
    May 23, 2020 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.