Hi Rui, thank you this is helpful, however, I would like the values in the or above the bars.
I have tried 'dodge' but not working correctly. ggplot(tmp, aes(x=Region, y=ProductLineID, fill=ProductLineFlag)) + #Getting worse again geom_bar(stat ="identity") + geom_col(position = 'dodge') + facet_grid("InOutFlagAlpha") Thoughts? WHP From: Rui Barradas <ruipbarra...@sapo.pt> Sent: Friday, February 28, 2020 11:06 AM To: Bill Poling <bill.pol...@zelis.com>; r-help (r-help@r-project.org) <r-help@r-project.org> Subject: Re: [R] Help with ggplot plot [External Email] Hello, If you want faceting, a square grid can do it. ggplot(tmp, aes(x=Region, y=ProductLineID, fill=Region)) + geom_bar(stat = "identity") + facet_grid(InOutFlagAlpha ~ ProductLineFlag) Hope this helps, Rui Barradas Às 16:50 de 28/02/20, Bill Poling escreveu: > #RStudio Version 1.2.5019 > sessionInfo() > # R version 3.6.2 (2019-12-12) > #Platform: x86_64-w64-mingw32/x64 (64-bit) > #Running under: Windows 10 x64 (build 17134) > > Hello, I am sure I am missing something simple. > > Here is my data, its aggregated and if need be I can unaggregate I guess: > > dput(tmp) > structure(list(InOutFlagAlpha = c("NO ", "YES", "NO ", "YES", > "NO ", "YES", "NO ", "YES", "NO ", "YES", "NO ", "YES", "NO ", > "YES", "NO ", "YES", "NO ", "YES", "NO ", "YES"), ProductLineFlag = > structure(c(1L, > 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, > 1L, 2L, 2L), .Label = c("ACH", "CARD"), class = "factor"), Region = > structure(c(1L, > 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, > 5L, 5L, 5L), .Label = c("Frontier", "Midwest", "Northeast", "Pacific", > "South"), class = "factor"), ProductLineID = c(7163L, 34212L, > 35891L, 54177L, 8873L, 34008L, 52017L, 67881L, 7408L, 29430L, > 64108L, 70532L, 5984L, 21720L, 49030L, 60211L, 7330L, 34876L, > 46387L, 75893L)), row.names = c(NA, -20L), class = "data.frame") > > |InOutFlagAlpha |ProductLineFlag | Region| ProductLineID| > |:--------------|:---------------|---------:|-------------:| > |NO |ACH | Frontier| 7163| > |YES |ACH | Frontier| 34212| > |NO |CARD | Frontier| 35891| > |YES |CARD | Frontier| 54177| > |NO |ACH | Midwest| 8873| > |YES |ACH | Midwest| 34008| > |NO |CARD | Midwest| 52017| > |YES |CARD | Midwest| 67881| > |NO |ACH | Northeast| 7408| > |YES |ACH | Northeast| 29430| > |NO |CARD | Northeast| 64108| > |YES |CARD | Northeast| 70532| > |NO |ACH | Pacific| 5984| > |YES |ACH | Pacific| 21720| > |NO |CARD | Pacific| 49030| > |YES |CARD | Pacific| 60211| > |NO |ACH | South| 7330| > |YES |ACH | South| 34876| > |NO |CARD | South| 46387| > |YES |CARD | South| 75893| > > I am trying to get the value from ProductLineID into the bars > > I have slowly stepped through to the point of having everything but the > values. > > Appreciate any advice, thank you. > > WHP > > #1 > ggplot(tmp, aes(x=Region, y=ProductLineID, fill=Region)) + > geom_bar(stat = "identity") > #2 > ggplot(tmp, aes(x=Region, y=ProductLineID, fill=Region)) + > geom_bar(stat = "identity") + > facet_grid("InOutFlagAlpha") > #3 > ggplot(tmp, aes(x=Region, y=ProductLineID, fill=Region)) + > geom_bar(stat ="identity") + > facet_grid("InOutFlagAlpha") > #4 > ggplot(tmp, aes(x=Region, y=ProductLineID, fill=Region)) + > geom_bar(stat ="identity",position = 'dodge') + > facet_grid("InOutFlagAlpha") > #5 > ggplot(tmp, aes(x=Region, y=ProductLineID, fill=ProductLineFlag)) + > geom_bar(stat ="identity",position = 'dodge') + > facet_grid("InOutFlagAlpha") > #6 > ggplot(tmp, aes(x=Region, y=ProductLineID, fill=ProductLineFlag)) + #Best so > far > geom_bar(stat ="identity") + > geom_col() + > facet_grid("InOutFlagAlpha") > #7 > ggplot(tmp, aes(x=Region, y=ProductLineID, fill=ProductLineFlag)) + #Not > working > geom_bar(stat ="identity") + > geom_col(position = 'dodge') + > facet_grid("InOutFlagAlpha") > > WHP > > > Confidentiality Notice\ \ This email and the attachments...{{dropped:11}} > > ______________________________________________ > mailto:R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > Confidentiality Notice This email and the attachments may contain information which is privileged and/or confidential and is intended for the business and/or confidential use of the recipient only. Such information may be protected by applicable State and/or Federal laws from disclosure or unauthorized use. If you are not the intended recipient, you are hereby notified that any disclosure is strictly prohibited. If you have received this email in error, please contact the sender immediately. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.