[R] Help with ggplot plot
Rui Barradas
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Fri Feb 28 18:05:33 CET 2020
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}}
>
> ______________________________________________
> R-help using 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.
>
More information about the R-help
mailing list