GGPlot2 - OnePageR - Togaware

16 downloads 327 Views 2MB Size Report
May 22, 2015 - We add a theme() to remove the legend that would be displayed by ..... flow for a small business over a y
Hands-On and will be automatically chosen if not specified, with a message displayed to inform us of this. The formula specified, formula=y~ s(x, bs="cs") is also the default for method="gam". Typical of scatter plots of big , formula=y~s(x, bs="cs"))

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + +

Page: 6 of 68

, formula=y~s(x, bs="cs")) facet_wrap(~location) theme(axis.text.x=element_text(angle=45, hjust=1))

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + + + +

Page: 7 of 68

, formula=y~s(x, bs="cs")) facet_wrap(~location) theme(axis.text.x=element_text(angle=45, hjust=1))

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + + + +

Page: 8 of 68

, formula=y~s(x, bs="cs")) facet_wrap(~location) theme(axis.text.x=element_text(angle=45, hjust=1))

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + + + +

Page: 9 of 68

, formula=y~s(x, bs="cs")) facet_wrap(~location) theme(axis.text.x=element_text(angle=45, hjust=1))

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + + + +

Page: 10 of 68

)

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% +

Page: 16 of 68

x=paste0("Wind Direction 3pm\n", Sys.time()) y="Number of Days" fill="Tomorrow")

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + + + , , + , , ,

Page: 17 of 68

, fill="grey")

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% +

Page: 20 of 68

)

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + +

Page: 21 of 68

)

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + + +

Page: 22 of 68

) theme(legend.position="none")

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + + + +

Page: 23 of 68

, geom="bar") theme(legend.position="none")

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + +

Page: 24 of 68

, geom="bar") theme(legend.position="none", axis.text.x=element_text(angle=90))

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + +

Page: 25 of 68

, geom="bar") theme(legend.position="none") coord_flip()

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% + + +

Page: 26 of 68

, geom="bar") theme(legend.position="none") coord_flip()

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% + + +

Page: 27 of 68

, geom="bar") stat_summary(fun., geom="errorbar", conf.int=0.95, width=0.35) theme(legend.position="none") coord_flip()

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% + + + +

Page: 28 of 68

) theme(legend.position="none") coord_flip() geom_text(stat="bin", color="white", hjust=1.0, size=3, aes(y=..count.., label=..count..))

%>% %>% + + + +

Exercise: Instead of plotting the counts, plot the mean temp 3pm, and include the textual value.

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

Page: 29 of 68

) theme(legend.position="none") coord_flip() geom_text(stat="bin", color="white", hjust=1.0, size=3, aes(y=..count.., label=scales::comma(..count..)))

%>% %>% + + + +

Exercise: Do this without having to use scales::, perhaps using a format.

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

Page: 30 of 68

)

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% + + +

Page: 32 of 68

)

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% + + +

Page: 33 of 68

)

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% + + +

Page: 34 of 68

) theme(legend.position="none")

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% + + + +

Page: 35 of 68

) theme(legend.position="none")

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% + + + +

Page: 36 of 68

)

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% + +

Page: 38 of 68

)

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% + +

Page: 39 of 68

)

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% + + +

Page: 40 of 68

, axis.text.x=element_text(angle=45, hjust=1)) facet_wrap(~location)

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% + + + +

Page: 41 of 68

, vjust=ifelse(cash$Direction == "Debit", 1.3, -0.3)) + theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) + ylab("Balance in Thousand Dollars") + ggtitle("Annual Cash Flow Analysis")

DR AF

T

Annual Cash Flow Analysis

Balance in Thousand Dollars

Advise -4

Adv -8

40

20 Consult

15 Sales

Direction Debit

Tax -7

Credit Net

11 Salary

20

0

8 Rebate

Elect -4

IT -5

30 Start

56 End

Transaction

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

Page: 44 of 68

) theme(axis.text.x=element_text(angle=45, hjust=1), legend.position=c(0.25, 1), legend.justification=c(0.0, 1.0), legend.direction="horizontal", legend.background=element_rect(fill="transparent"), legend.key=element_rect(fill="transparent", colour="transparent"))

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% +

Page: 49 of 68

, fill="orange", color="black") coord_polar(theta="x", start=-pi/12)

Copyright © 2013-2014 [email protected]

Module: GGPlot2O

%>% %>% %>% %>% %>% + +

Page: 50 of 68

, alpha=.2, size=1) p2 + ggtitle("Fitted Max Temperature Curves")

DR AF

T

p p1 p1 p1 p1

p3