Plot is not coming up in Plot Area

Hi, I need help. Actually my plot is not coming up though the code is running. I upgraded my R package but still not working.

See the FAQ: How to do a minimal reproducible example reprex for beginners.

Cut and paste the code below. It should produce a blank canvas—because nothing more was requested.

suppressPackageStartupMessages({
  library(ggplot2)
})

ggplot(mtcars,(aes(mpg,hp)))

The following snippet plots the data as points

suppressPackageStartupMessages({
  library(ggplot2)
})

ggplot(mtcars,(aes(mpg,hp))) + geom_point()

Thank you so much....This worked really well but I dont know why the code which put didnt work -

library(ggplot2)

CPR_RATE <- read_excel("E:/SK Patodia Group/NFHS 4 DATA/CPR RATE.xlsx")
dim(CPR_RATE)
str(CPR_RATE)
a <- ggplot(CPR_RATE,aes(x=injectables,y=modern_cpr))
a <- a + geom_blank() + ylim(0,75) + xlim(0,10)

geom_blank is just that, blank. Try geom_point

okay thanks....let me try

Hi, I run the program as suggested by you..it was running smoothly but today again the same problem started.
I copy this code but again plot is not coming.

Please post the code you used today.

By the way you probably never should have **geom_blank() ** in your code.

As far as I can see

ggplot(mydata, aes(x, y))

and

ggplot(mydata, aes(x, y)) + geom_blank()

are equivalent.

1 Like

Hi,,,,,thanks for your quick reply! Today I used the following simple code for my data -
library(ggplot2)
ggplot(CPR_RATE, aes(injectables, modern_cpr))

You need to use geoms (such as geom_point) (but not geom_blank) to have content in your chart.

1 Like

Hey, I used this code but plot is empty. No bar or line graph is coming.
library(ggplot2)
ggplot(CPR_RATE, aes(injectables, modern_cpr))
ggplot(CPR_RATE, aes(injectables, modern_cpr) + geom_line()

If you are making a single ggplot, don't use ggplot twice. I saw you + geom_point however you dropped a necessary ) which derailed you.

Such a great help, Actually I am new for R ....can you guide me that I am plotting a graph but I want different color for dot points so which code should I use.

As a beginner to R you may benefit from studying this useful book.
https://r4ds.had.co.nz/
Particularly chapter 3

This is how I learned about ggplot2

1 Like

sure thanks a lot for your kind help

and maybe this by Thomas:
https://www.youtube.com/watch?v=h29g21z0a68

https://www.youtube.com/watch?v=0m4yywqNPVY

it helped me a lot.

Hi......I am reading book suggested by you....its working.....thanks a lot!

Hey can you look at the code below given -

library(ggplot2)
ggplot(MCPR_RATE_STATE_WISE) +
geom_point(mapping = aes(x = prevalence, y = cpr))

error is coming -

ggplot(MCPR_RATE_STATE_WISE) +

  • geom_point(mapping = aes(x = prevalence, y = cpr))
    Error in FUN(X[[i]], ...) : object 'prevalence' not found

Can u suggest ???

What does

names(MCPR_RATE_STATE_WISE)

Give you ?

You make the graph and save it to "a"
You never print "a"
You could
a<ggplot(CPR_RATE, aes(x=injectables, y=modern_cpr))
a+ geom_point() + ylim(0,75) + xlim(1,10)

or you could add another line with only a

This is data sheet name actually

I am using the following code for bar graph.

ggplot(data = demo) +
geom_bar(mapping = aes(x = cut, colour = cut))

But in bar graph, counts are coming similar though they differ in frequency.