This might not answer your specific question directly, but you may find the following documentations very helpful if you're new to R.

This is the website for “R for Data Science” . This book will teach you how to do data science with R: You’ll learn how to get your data into R, get it into the most useful structure, transform it, visualise it and model it. In this book, you will find a practicum of skills for data science.

And a bit more specifically regarding creating visualisations:

This chapter will teach you how to visualise your data using ggplot2. R has several systems for making graphs, but ggplot2 is one of the most elegant and most versatile. ggplot2 implements the grammar of graphics , a coherent system for describing and building graphs. With ggplot2, you can do more faster by learning one system and applying it in many places.

There are even more excellent online books available, to start with:

Thank you for the response. Can you please tell me how should I re-write that? and where are the mistakes? did not I answered the first and second questions in my code?