Not really sure I understand what you want. Here is some code to
consider:
################
library(ggplot2)
library(dplyr)
library(tidyr)
dta <- read.table( text =
"samp.N RSQ MRB_uc MRB_sb MRB_bp
50 0.3 1.42 37.6 37.6
50 0.4 8.61 43.1 43.1
50 0.5 7.41 31.6 31.6
50 0.6 5.06 21.5 21.5
50 0.7 3.38 14.1 14.1
50 0.8 -1.07 5.16 5.16
100 0.3 -6.41 40.3 40.3
100 0.4 -10.6 21.0 21.0
100 0.5 -9.02 13.2 13.2
100 0.6 -9.85 5.14 5.14
100 0.7 -7.94 2.08 2.08
100 0.8 -4.81 1.28 1.28
", header = TRUE )
dta2 <- ( dta
%>% mutate( samp.N = factor( samp.N )
, RSQ = factor( RSQ )
)
%>% gather( Measure, value, -c( samp.N, RSQ ) )
)
ggplot( dta2, aes( x = RSQ, y = value, fill = samp.N ) ) +
geom_bar( stat = "identity", position = "dodge", colour = "black" ) +
facet_wrap( ~ Measure, ncol = 1, scale = "free_y" ) +
ylab( "" )
################
On Sat, 20 Apr 2019, Scott Colwell wrote:
I am trying to figure out how to create a hanging bar plot from dplyr.
I have used dplyr as follows:
table4 <- cr %>%
group_by(samp.N, RSQ) %>%
summarize(
MRB_uc = mean(CF.F1F2/0.40*100)-100,
MRB_sb = mean(SBC.F1F2.Alpha/0.40*100) - 100,
MRB_bp = mean(BPC.F1F2.Alpha/0.40*100) - 100
)
which provides me with this:
samp.N RSQ MRB_uc MRB_sb MRB_bp
<dbl> <dbl> <dbl> <dbl> <dbl>
1 50 0.3 1.42 37.6 37.6
2 50 0.4 8.61 43.1 43.1
3 50 0.5 7.41 31.6 31.6
4 50 0.6 5.06 21.5 21.5
5 50 0.7 3.38 14.1 14.1
6 50 0.8 -1.07 5.16 5.16
7 100 0.3 -6.41 40.3 40.3
8 100 0.4 -10.6 21.0 21.0
9 100 0.5 -9.02 13.2 13.2
10 100 0.6 -9.85 5.14 5.14
11 100 0.7 -7.94 2.08 2.08
12 100 0.8 -4.81 1.28 1.28
What I want to do is create a hanging bar plot with the x-axis being samp.N
value by RSQ value. The bars are then values of MRB_uc, MRB_sb, and MRB_bp.
Given some values are negative, some bars will be above zero and others below
(hence the hanging bar plot)
I don't have any code yet as I am completely unfamiliar with how to do this.
Any suggestions would be really appreciated.
Thank you!
Scott
--
Scott R. Colwell, PhD
[[alternative HTML version deleted]]
______________________________________________
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.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnew...@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
______________________________________________
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.