Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in R Programming by (50.2k points)

In the following syntax, the height of the bars represents the count of each group in this variable "color":

ggplot(diamonds, aes(color, fill = cut)) +geom_bar()

But I am not able to understand what the following code is doing:

ggplot(diamonds, aes(color, fill = cut)) + geom_bar(alpha=0.5, position = "identity")

Can you please explain what position and alpha are doing?

1 Answer

0 votes
by (107k points)

Say for instance, in R programming when you plot any graph using ggplot2 and inside the ggplot function you are having position='dodge' in that it helps to place the multiple bars for different cuts, separated by color and it doesn't layer all the cut bars on top of each other.

ggplot(diamonds, aes(color, fill = cut)) + geom_bar(alpha=0.5, position = "dodge")

 image

ggplot(diamonds, aes(color, fill = cut)) +  geom_bar(alpha=0.5, position = "identity")

image

Note: The colors get distorted because the 'Fair' cut is in front.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...