can anyone explain format in ggplot2

I wrote both codes,both give same results , so was it just coincidence or both formats are correct?
ggplot(data = penguins,aes(x=flipper_length_mm,y=body_mass_g))+geom_point()
and
ggplot(data=penguins) + geom_point(mapping = aes(x=flipper_length_mm,,y=body_mass_g))

Both are the same. The difference will be if you add any further objects: in the first example the aesthetic mapping is inherited by further objects, but not in the second.

1 Like

Like said @martin.R , are the same. Im could add extra comment says that in ggplot(data=penguins) you could specify the data frame and the next others geom_ you put only the names of variables in aes.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.