I want to visualise the proportional data (Nij/n) about the sinus (independent) and arr/AHB (dependent variable) cases in females and males by R.
ggplot2
approach and any other is welcome!
Pseudocode
- histogram of the second and third columns for the groups N11.1, ..., N32.1
Code
N11.1 N22.1 N33.1 N44.1 N21.1 N31.1 N32.1
Sinus 1.0 0.0 0.0 0.0 0.0 0.0 12.0
Arr/AHB 1.0 0.0 0.0 0.1 0.0 0.0 20.9
N11.1 N22.1 N33.1 N44.1 N21.1 N31.1 N32.1
Sinus 1.0 0.0 0.0 0.0 0.0 0.0 4.0
Arr/AHB 1.0 0.0 0.0 0.0 0.0 0.0 24.0
The first column has the row.names. Code with the data
library("ggplot2")
data.female <- structure(list(N11.1 = structure(c(3L, 3L), .Label = c("", "0.0",
"1.0", "N11"), class = "factor"), N22.1 = structure(c(2L, 2L), .Label = c("",
"0.0", "2.0", "N22"), class = "factor"), N33.1 = structure(c(2L,
2L), .Label = c("", "0.0", "N33"), class = "factor"), N44.1 = structure(2:3, .Label = c("",
"0.0", "0.1", "0.2", "N44"), class = "factor"), N21.1 = structure(c(2L,
2L), .Label = c("", "0.0", "N21"), class = "factor"), N31.1 = structure(c(2L,
2L), .Label = c("", "0.0", "N31"), class = "factor"), N32.1 = structure(c(5L,
7L), .Label = c("", "0.0", "10.8", "11.0", "12.0", "17.0", "20.9",
"22.8", "24.0", "3.0", "4.0", "44.0", "N32"), class = "factor")), .Names = c("N11.1",
"N22.1", "N33.1", "N44.1", "N21.1", "N31.1", "N32.1"), row.names = c("Sinus",
"Arr/AHB"), class = "data.frame")
data.male <- structure(list(N11.1 = structure(c(3L, 3L), .Label = c("", "0.0",
"1.0", "N11"), class = "factor"), N22.1 = structure(c(2L, 2L), .Label = c("",
"0.0", "2.0", "N22"), class = "factor"), N33.1 = structure(c(2L,
2L), .Label = c("", "0.0", "N33"), class = "factor"), N44.1 = structure(c(2L,
2L), .Label = c("", "0.0", "0.1", "0.2", "N44"), class = "factor"),
N21.1 = structure(c(2L, 2L), .Label = c("", "0.0", "N21"), class = "factor"),
N31.1 = structure(c(2L, 2L), .Label = c("", "0.0", "N31"), class = "factor"),
N32.1 = structure(c(11L, 9L), .Label = c("", "0.0", "10.8",
"11.0", "12.0", "17.0", "20.9", "22.8", "24.0", "3.0", "4.0",
"44.0", "N32"), class = "factor")), .Names = c("N11.1", "N22.1",
"N33.1", "N44.1", "N21.1", "N31.1", "N32.1"), row.names = c("Sinus",
"Arr/AHB"), class = "data.frame")
Attempt for a single data row
data.female.sinus <- data.female[1:1,1:7]
print(data.female.sinus)
g <- ggplot(data.female.sinus)
g + geom_bar()
#Warning messages:
#1: In min(x, na.rm = na.rm) :
# no non-missing arguments to min; returning Inf
#2: In max(x, na.rm = na.rm) :
# no non-missing arguments to max; returning -Inf
#3: In min(diff(sort(x))) : no non-missing arguments to min; returning Inf
#4: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
#5: Computation failed in `stat_count()`:
#arguments imply differing number of rows: 0, 1
#null device
Expected output: histogram in comparison between male and female, with emphasis that Arr/AHB is the dependent variable
Testing hhh's answer
I do not understand why you cannot use the given data with column names like without column names
Sinus <- c(1,0,0,0,0,0,12)
ArrAHB <- c(1,0,0,0.1,0,0,20.9)
# Things work with this data
Sinus <- data.female[1, 1:7]
ArrAHB <- data.female[2, 1:7]
# Things do not work with this data which has column names
Labels <- c("N11.1","N22.2","N33.1","N44.1","N21.1","N31.1","N32.1")
ID <- c("Sinus","Arr/AHB")
data.female <- data.frame(Sinus,ArrAHB,row.names=Labels)
data.female <- t(data.female)
barchart(data.female,auto.key=list(space='right'))
R: 3.3.1
OS: Debian 8.5
See Question&Answers more detail:
os