0% found this document useful (0 votes)
30 views3 pages

R Script 0503

The document discusses different position adjustment functions in ggplot2 including position_stack(), position_dodge(), position_fill(), and position_identity(). It shows examples of using these functions with geom_bar() to control the positioning of bars in bar plots. The document also demonstrates facetting with facet_wrap() to divide the plot area into a grid by one or more variables.

Uploaded by

pjm1278
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

R Script 0503

The document discusses different position adjustment functions in ggplot2 including position_stack(), position_dodge(), position_fill(), and position_identity(). It shows examples of using these functions with geom_bar() to control the positioning of bars in bar plots. The document also demonstrates facetting with facet_wrap() to divide the plot area into a grid by one or more variables.

Uploaded by

pjm1278
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#position_adjustment()함수군

ggplot(data=mtcars) + geom_bar(mapping = aes(x=cyl))

ggplot(data=mtcars) +

geom_bar(mapping = aes(x=cyl, fill=as.factor(am)))

ggplot(data=mtcars) +

geom_bar(mapping = aes(x=cyl, fill=as.factor(am), position = "stack"))

#position_dodge()함수

ggplot(mtcars, aes(x=factor(cyl), fill=factor(vs))) +

geom_bar()

ggplot(mtcars, aes(x=factor(cyl), fill=factor(vs))) +

geom_bar(width =0.5, position=position_dodge(width=0.5))

ggplot(mtcars, aes(x=factor(cyl), fill=factor(vs))) +

geom_bar(position=position_dodge(0.1))

#position_fill()함수

ggplot(mtcars, aes(x=factor(cyl), fill=factor(vs))) +

geom_bar(position="fill")

ggplot(mtcars, aes(x=factor(cyl), fill=factor(vs))) +

geom_bar()

#position_identity()함수

ggplot(data=mtcars) +

geom_bar(mapping=aes(x=cyl, fill=as.factor(am), position="identity"))

ggplot(data=mtcars) +
geom_bar(mapping=aes(x=cyl, fill=as.factor(am)))

#패시팅(facetting)

#1.그리드(grid)형과 2.래핑(wrapped)형

ggplot(data=mpg, aes(x=displ, y=hwy)) +

geom_point() +

facet_wrap(~class)

?tips

head(tips, n=10)

View(tips)

ggplot(data=tips, aes(x=total_bill, y=tip/total_bill)) +

geom_point(shape=1) +

facet_wrap(~day, ncol=2)

ggplot(data=mpg, aes(x=displ, y=hwy)) +

geom_point() +

facet_wrap(~class, nrow=4)

ggplot(data=mpg, aes(cty, hwy)) +

geom_point() +

facet_wrap(~drv)

ggplot(data=mpg, aes(cty, hwy)) +

geom_point() +
facet_wrap(~drv + year)

You might also like