Related
I'm trying to make an object that I can use in the package phyloseq, but I can't seem to get it to work. Below is a small subset of my data. First is an otu table, the second has the taxa.
OTUs <- dput(OTU_table[1:5,])
structure(list(OTU_ID = c("OTU_1", "OTU_6", "OTU_16", "OTU_2",
"OTU_216"), V2T4r5Croot = c(3505L, 5L, 124L, 0L, 8L), V2T4r5Broot = c(18880L,
18390L, 1L, 10233L, 0L), R6T2r5Croot = c(82973L, 5195L, 444L,
93L, 7L), V2T2r2Broot = c(13747L, 79L, 1603L, 33L, 0L), R3T2r5Broot = c(11212L,
2L, 462L, 33977L, 0L), V2T2r2Croot = c(63779L, 354L, 5204L, 374L,
0L), R3T4r5Croot = c(60109L, 1518L, 4067L, 875L, 2L), R3T1r5Aroot = c(28412L,
3161L, 626L, 3465L, 131L), R3T4r2Croot = c(40569L, 110L, 575L,
8642L, 0L), V2T2r5Aroot = c(22800L, 2225L, 1334L, 12185L, 4L),
R6T2r5Broot = c(50017L, 5739L, 4199L, 0L, 0L), R6T1r1Broot = c(52756L,
0L, 35L, 490L, 0L), R6T1r2Croot = c(14828L, 10227L, 180L,
3973L, 10L), V2T1r6Aroot = c(40317L, 146L, 543L, 5975L, 36L
), R6T2r1Broot = c(13801L, 524L, 189L, 6121L, 0L), V2T4r1Broot = c(58001L,
21L, 247L, 2359L, 5L), R6T2r6Croot = c(79608L, 715L, 384L,
13121L, 0L), R3T2r1Aroot = c(7938L, 187L, 2305L, 212L, 0L
), R6T2r6Aroot = c(20243L, 1098L, 320L, 10632L, 9L), V2T1r5Broot = c(11102L,
156L, 200L, 8205L, 0L), V2T4r2Aroot = c(7641L, 393L, 53L,
366L, 27L), R6T4r5Croot = c(5L, 68L, 7192L, 4L, 0L), R6T4r5Broot = c(40122L,
92L, 29L, 64631L, 59L), R3T4r6Croot = c(49960L, 101L, 97L,
18846L, 0L), R6T2r2Aroot = c(81204L, 7801L, 1499L, 13245L,
6L), R3T4r5Aroot = c(108839L, 5072L, 1894L, 1957L, 55L),
R3T2r1Broot = c(624L, 0L, 62L, 3687L, 0L), R6T1r5Croot = c(67805L,
0L, 238L, 2L, 0L), V2T4r6Croot = c(43210L, 24L, 0L, 33L,
0L), R3T1r6Aroot = c(6419L, 274L, 1062L, 2411L, 79L), R3T2r2Croot = c(53908L,
34726L, 3497L, 82L, 144L), R3T4r2Aroot = c(10503L, 48L, 23L,
27764L, 0L), R3T2r5Aroot = c(2386L, 79L, 39L, 1805L, 0L),
V2T2r1Croot = c(20324L, 318L, 14L, 1192L, 0L), V2T1r5Aroot = c(3933L,
33L, 6L, 3785L, 0L), V2T1r1Broot = c(99803L, 7377L, 203L,
1098L, 75L), R3T4r6Aroot = c(16601L, 1113L, 217L, 309L, 33L
), R3T2r1Croot = c(135822L, 24308L, 4986L, 219L, 230L), V2T1r5Croot = c(12444L,
139L, 32L, 211L, 0L), R3T1r6Croot = c(3957L, 9L, 117L, 293426L,
0L), R6T1r2Broot = c(92870L, 43L, 625L, 616L, 0L), V2T2r2Aroot = c(26697L,
654L, 130L, 31056L, 0L), R3T2r6Broot = c(82471L, 22990L,
3253L, 955L, 4L), R6T1r1Aroot = c(11187L, 0L, 5L, 0L, 0L),
R6T1r6Broot = c(6016L, 72L, 386L, 3368L, 0L), R3T1r1Aroot = c(55133L,
5854L, 494L, 1694L, 45L), V2T1r2Aroot = c(9346L, 139L, 17L,
64L, 0L), R3T4r1Aroot = c(84510L, 4049L, 1441L, 1193L, 5L
), R6T2r5Aroot = c(38997L, 33L, 273L, 967L, 0L), R3T4r2Broot = c(54402L,
565L, 567L, 9L, 0L), R3T1r2Broot = c(42977L, 24L, 132L, 3L,
7L), R6T1r5Aroot = c(5433L, 39L, 16L, 2L, 0L), R3T1r1Croot = c(4356L,
0L, 0L, 24719L, 0L), R3T4r5Broot = c(39402L, 6424L, 151L,
0L, 0L), R6T1r2Aroot = c(67639L, 14L, 16L, 1L, 0L), R3T2r5Croot = c(12136L,
3420L, 193L, 98L, 0L), R3T1r5Croot = c(21358L, 2876L, 347L,
9850L, 0L), V2T1r6Broot = c(16975L, 2L, 273L, 1397L, 98L),
R6T1r1Croot = c(7403L, 18L, 36L, 2112L, 0L), R3T1r1Broot = c(18301L,
1122L, 276L, 6921L, 7L), V2T2r6Croot = c(59794L, 2560L, 92L,
12437L, 0L), R6T1r5Broot = c(58396L, 1284L, 119L, 21078L,
0L), V2T4r6Broot = c(10496L, 773L, 1603L, 1950L, 19L), V2T1r6Croot = c(34687L,
9560L, 38L, 19L, 1L), R3T4r1Broot = c(23020L, 78L, 276L,
160L, 66L), V2T4r1Aroot = c(32591L, 91L, 197L, 308L, 0L),
V2T4r6Aroot = c(35314L, 3L, 1550L, 1775L, 0L), V2T2r6Aroot = c(12424L,
884L, 149L, 481L, 0L), V2T2r1Aroot = c(6721L, 52L, 203L,
4286L, 0L), R3T2r2Broot = c(26251L, 447L, 326L, 4834L, 0L
), V2T4r2Broot = c(27830L, 2404L, 1131L, 98L, 18L), R6T1r6Aroot = c(11818L,
14L, 34L, 1L, 0L), V2T1r1Croot = c(7961L, 5L, 376L, 2802L,
0L), R6T2r2Croot = c(25329L, 15L, 63L, 76L, 0L), R6T2r2Broot = c(1002L,
0L, 153L, 26L, 0L), R6T2r1Aroot = c(38869L, 11953L, 1987L,
2639L, 0L), V2T4r5Aroot = c(1838L, 18L, 1L, 47981L, 5L),
R6T4r1Aroot = c(3323L, 16L, 3L, 7212L, 0L), V2T2r5Croot = c(22124L,
1037L, 395L, 1515L, 296L), R3T4r6Broot = c(4112L, 0L, 0L,
1L, 0L), R3T1r5Broot = c(4443L, 120L, 528L, 1176L, 0L), V2T2r6Broot = c(2068L,
55L, 11L, 7180L, 0L), R3T2r2Aroot = c(4962L, 277L, 35L, 1L,
7L), V2T1r1Aroot = c(18506L, 0L, 44L, 93L, 0L), R3T1r2Aroot = c(19779L,
2L, 162L, 51355L, 8L), R6T2r1Croot = c(913L, 4L, 26L, 10L,
0L), V2T2r5Broot = c(7309L, 69L, 63L, 38L, 15L), V2T4r1Croot = c(8043L,
231L, 1351L, 787L, 18L), R3T1r6Broot = c(1973L, 1L, 0L, 40482L,
0L), R3T4r1Croot = c(4004L, 326L, 12L, 2020L, 11L), V2T1r2Croot = c(2712L,
21L, 43L, 2127L, 0L), V2T4r2Croot = c(3711L, 118L, 0L, 1487L,
50L), R3T2r6Croot = c(1491L, 290L, 55L, 33L, 0L), R6T1r6Croot = c(8541L,
0L, 0L, 0L, 0L), R6T2r6Broot = c(2561L, 6L, 2L, 387L, 0L),
V2T2r1Broot = c(2128L, 315L, 180L, 1483L, 0L), V2T1r2Broot = c(2363L,
78L, 260L, 2182L, 0L), R3T2r6Aroot = c(486L, 0L, 191L, 1209L,
0L), R3T1r2Croot = c(6014L, 18L, 126L, 587L, 0L), NC1root = c(5L,
0L, 0L, 0L, 0L), R6T4r6Aroot = c(246L, 3L, 7L, 83L, 0L)), row.names = c(NA,
5L), class = "data.frame")
and
taxa <- dput(taxa[c(1,2,6,16,216),])
structure(list(OTU_ID = c("OTU_1", "OTU_2", "OTU_6", "OTU_16",
"OTU_216"), Kingdom = c("Fungi_1", "Fungi_1", "Fungi_1", "Fungi_1",
"Fungi_1"), Phylum = c("Ascomycota_1", "Ascomycota_1", "", "Ascomycota_1",
"Basidiomycota_1"), Class = c("Sordariomycetes_1", "Dothideomycetes_1",
"", "Dothideomycetes_1", "Tremellomycetes_1"), Order = c("Hypocreales_1",
"Pleosporales_1", "", "Pleosporales_1", "Tremellales_1"), Family = c("Nectriaceae_1",
"Corynesporascaceae_1", "", "Pleosporaceae_1", "Trimorphomycetaceae"
), Genus = c("Fusarium_1", "Corynespora_1", "", "Alternaria_1",
"Saitozyma"), Species = c("", "Corynespora cassiicola ", "",
"", "")), row.names = c(1L, 2L, 6L, 16L, 216L), class = "data.frame")
Here's some code I've tried:
OTUs1 <- as.matrix(OTUs)
taxa1 <- as.matrix(taxa)
OTUs2 = otu_table(OTUs1, taxa_are_rows = TRUE)
physeq <- phyloseq(OTUs2, taxa1)
I get this error when I run the code to try and make the object:
Error in phyloseq(OTUs2, taxa1) :
Problem with OTU/taxa indices among those you provided.
Check using intersect() and taxa_names()
I assume that you are getting this error because the row.names between both matrices do not match. The following steps should resolve your error:
require("dplyr")
# Add OTU_IDs as row.names
row.names(taxa) <- taxa[,'OTU_ID']
row.names(OTUs) <- OTUs[,'OTU_ID']
# Remove the OTU_ID column
taxa <- taxa[,colnames(taxa) != 'OTU_ID']
OTUs <- OTUs[,colnames(OTUs) != 'OTU_ID']
# Make sure that OTU_IDs in taxa and OTUs overlap and are in the same order
ids <- dplyr::intersect(row.names(taxa), row.names(OTUs))
taxa <- taxa[ids,]
OTUs <- OTUs[ids,]
# Convert to phyloseq object
taxa <- tax_table(as.matrix(taxa))
OTUs <- otu_table(as.matrix(OTUs), taxa_are_rows = TRUE)
physeq <- phyloseq(taxa, OTUs)
I am trying to rotate the header for a datatable. I was able to rotate the header but the rotated header is not aligning with the columns. This is what I have now:
I referenced this for my code : header direction in shiny data table
Here is my code:
datatable(df, rownames = F,class = c("compact"),options = list(paging = F, autoWidth = T,searching= FALSE,
scrollX=T,
initComplete = JS("function(settings, json) {$(this.api().table().header()).css({'font-size' : '12px'});}"),
headerCallback = JS(
"function(thead, data, start, end, display){
var $ths = $(thead).find('th');
$ths.css({'vertical-align': 'bottom', 'white-space': 'nowrap'});
var betterCells = [];
$ths.each(function(){
var cell = $(this);
var newDiv = $('<div>', {height: 'auto', width: cell.height()});
var newInnerDiv = $('<div>', {text: cell.text()});
newDiv.css({margin: 'auto'});
newInnerDiv.css({
transform: 'rotate(220deg)',
'writing-mode': 'tb-rl',
'white-space': 'nowrap'
});
newDiv.append(newInnerDiv);
betterCells.push(newDiv);
});
$ths.each(function(i){
$(this).html(betterCells[i]);
});
}"
))) %>%
formatStyle(columns = c(1:19), `font-size` = '12px')
DATA:
structure(list(diag_category_name = structure(1:18, .Label = c("AIDS",
"Any malignancy", "Cerebrovascular disease", "Chronic pulmonary disease",
"Congestive heart failure", "Dementia", "Diabetes (mild to moderate)",
"Diabetes with chronic complications", "Hemoplegia or paralegia",
"Metastatic solid tumor", "Mild liver disease", "Moderate to severe liver disease",
"Myocardial infarction", "No Charlson Comorbidity", "Peptic ulcer disease",
"Peripheral vascular disease", "Renal disease", "Rheumatologic disease"
), class = "factor"), AIDS = c(20L, 6L, 3L, 5L, 1L, NA, NA, NA,
1L, 14L, 2L, NA, 1L, NA, NA, 3L, 5L, NA), `Any malignancy` = c(6L,
1051L, 108L, 209L, 106L, 34L, 130L, 158L, 14L, NA, 92L, 10L,
86L, NA, 37L, 190L, 161L, 32L), `Cerebrovascular disease` = c(3L,
108L, 421L, 122L, 105L, 44L, 47L, 94L, 35L, 303L, 35L, 7L, 67L,
NA, 23L, 165L, 111L, 15L), `Chronic pulmonary disease` = c(5L,
209L, 122L, 726L, 146L, 34L, 80L, 152L, 23L, 505L, 84L, 15L,
90L, NA, 43L, 234L, 173L, 31L), `Congestive heart failure` = c(1L,
106L, 105L, 146L, 381L, 27L, 37L, 124L, 15L, 269L, 43L, 3L, 121L,
NA, 18L, 166L, 160L, 16L), Dementia = c(NA, 34L, 44L, 34L, 27L,
109L, 11L, 32L, 5L, 74L, 5L, 1L, 26L, NA, 3L, 44L, 44L, 3L),
`Diabetes (mild to moderate)` = c(NA, 130L, 47L, 80L, 37L,
11L, 475L, NA, 8L, 335L, 58L, 9L, 36L, NA, 17L, 79L, 45L,
12L), `Diabetes with chronic complications` = c(NA, 158L,
94L, 152L, 124L, 32L, NA, 573L, 18L, 400L, 75L, 9L, 83L,
NA, 27L, 173L, 229L, 16L), `Hemoplegia or paralegia` = c(1L,
14L, 35L, 23L, 15L, 5L, 8L, 18L, 63L, 45L, 4L, NA, 13L, NA,
4L, 21L, 14L, 3L), `Metastatic solid tumor` = c(14L, NA,
303L, 505L, 269L, 74L, 335L, 400L, 45L, 2778L, 264L, 27L,
186L, NA, 79L, 492L, 455L, 68L), `Mild liver disease` = c(2L,
92L, 35L, 84L, 43L, 5L, 58L, 75L, 4L, 264L, 362L, NA, 29L,
NA, 22L, 73L, 70L, 8L), `Moderate to severe liver disease` = c(NA,
10L, 7L, 15L, 3L, 1L, 9L, 9L, NA, 27L, NA, 38L, 3L, NA, 6L,
11L, 10L, 1L), `Myocardial infarction` = c(1L, 86L, 67L,
90L, 121L, 26L, 36L, 83L, 13L, 186L, 29L, 3L, 277L, NA, 20L,
99L, 86L, 11L), `No Charlson Comorbidity` = c(NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 49L, NA, NA, NA,
NA), `Peptic ulcer disease` = c(NA, 37L, 23L, 43L, 18L, 3L,
17L, 27L, 4L, 79L, 22L, 6L, 20L, NA, 118L, 33L, 31L, 4L),
`Peripheral vascular disease` = c(3L, 190L, 165L, 234L, 166L,
44L, 79L, 173L, 21L, 492L, 73L, 11L, 99L, NA, 33L, 693L,
197L, 22L), `Renal disease` = c(5L, 161L, 111L, 173L, 160L,
44L, 45L, 229L, 14L, 455L, 70L, 10L, 86L, NA, 31L, 197L,
633L, 24L), `Rheumatologic disease` = c(NA, 32L, 15L, 31L,
16L, 3L, 12L, 16L, 3L, 68L, 8L, 1L, 11L, NA, 4L, 22L, 24L,
106L)), row.names = c(NA, -18L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x5638d466ed90>, sorted = "diag_category_name")
I have a fix. However, you may need to change some things depending on how you use this. For example, when you add x-axis scrolling overflow is hidden. When the table headings are tilted, there will be an overflow. That equates to some of the header labels getting hidden.
datatable(df1, rownames = F, class = c("compact"),
options = list(
paging = F, autoWidth = F,
searching= FALSE,
scrollX = F,
initComplete = JS("function(settings, json) {
$(this.api().table().header()).css({
'font-size' : '12px'});}"),
headerCallback = JS("function(thead, data, start, end, display){
var $ths = $(thead).find('th');
$ths.css({'vertical-align': 'top', 'padding': '4px 0px',
'transform': 'rotate(180deg)', 'border': 'none'});
var betterCells = [];
$ths.each(function(){
var cell = $(this);
var newDiv = $('<div>', {width: '13px', float: 'left'});
var newInnerDiv = $('<div>', {text: cell.text()});
newDiv.css({margin: 'auto'});
newInnerDiv.css({
'writing-mode': 'vertical-rl',
'white-space': 'nowrap',
'text-align': 'left',
'transform-origin': 'top left',
'transform': 'rotate(45deg)',
'overflow': 'visible'
});
newDiv.append(newInnerDiv);
betterCells.push(newDiv);
});
$ths.each(function(i){
$(this).html(betterCells[i]);
});}"))) %>%
formatStyle(columns = c(1:19), `font-size` = '12px')
There's a lot going on here, and most of it was your code. However, if you have any questions about what's happening here, just let me know.
I am using the magrittr pipe %>% to pipe an object into multiple arguments in the righthand side function, using curly braces to force :
data_bec <- dds_tmp %>%
{sva::ComBat_seq(
counts = . %>% SummarizedExperiment::assay(),
batch = . %>% magrittr::extract2("batch") %>% droplevels(),
covar_mod = cbind(
time = . %>% magrittr::extract2("time") %>% droplevels(),
treatment = . %>% magrittr::extract2("treatment") %>% droplevels()
)
)}
Which gives this error:
Error in unique.default(x, nmax = nmax) :
unique() applies only to vectors
However, the code below works:
data_bec <- dds_tmp %>%
{sva::ComBat_seq(
counts = SummarizedExperiment::assay(.),
batch = magrittr::extract2(., "batch") %>% droplevels(),
covar_mod = cbind(
time = magrittr::extract2(., "time") %>% droplevels(),
treatment = magrittr::extract2(., "treatment") %>% droplevels()
)
)}
I can't wrap my head around why magrittr::extract2(., "batch") %>% droplevels() works inside a function inside braces, but . %>% magrittr::extract2("batch") %>% droplevels() doesn't work. Is there an easy way to understand this behavior?
NB: My dds_tmp object is large and produced by DESeq2::sample_table. Here is a small example data set:
dds_tmp <- new(
"DESeqDataSet",
design = ~ 1,
dispersionFunction = function ()
NULL,
rowRanges = new(
"CompressedGRangesList",
unlistData = new(
"GRanges",
seqnames = new(
"Rle",
values = structure(integer(0), .Label = character(0), class = "factor"),
lengths = integer(0),
elementMetadata = NULL,
metadata = list()
),
ranges = new(
"IRanges",
start = integer(0),
width = integer(0),
NAMES = NULL,
elementType = "ANY",
elementMetadata = NULL,
metadata = list()
),
strand = new(
"Rle",
values = structure(integer(0), .Label = c("+",
"-", "*"), class = "factor"),
lengths = integer(0),
elementMetadata = NULL,
metadata = list()
),
seqinfo = new(
"Seqinfo",
seqnames = character(0),
seqlengths = integer(0),
is_circular = logical(0),
genome = character(0)
),
elementMetadata = new(
"DFrame",
rownames = NULL,
nrows = 0L,
listData = structure(list(), .Names = character(0)),
elementType = "ANY",
elementMetadata = NULL,
metadata = list()
),
elementType = "ANY",
metadata = list()
),
elementMetadata = new(
"DFrame",
rownames = NULL,
nrows = 50L,
listData = structure(list(), .Names = character(0)),
elementType = "ANY",
elementMetadata = new(
"DFrame",
rownames = NULL,
nrows = 0L,
listData = list(type = character(0), description = character(0)),
elementType = "ANY",
elementMetadata = NULL,
metadata = list()
),
metadata = list()
),
elementType = "GRanges",
metadata = list(),
partitioning = new(
"PartitioningByEnd",
end = c(
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
),
NAMES = c(
"0610005C13Rik", "0610007C21Rik", "0610007L01Rik", "0610007N19Rik",
"0610007P08Rik", "0610007P14Rik", "0610007P22Rik", "0610008F07Rik",
"0610009B14Rik", "0610009B22Rik", "0610009D07Rik", "0610009L18Rik",
"0610009O20Rik", "0610010B08Rik", "0610010F05Rik", "0610010K14Rik",
"0610010O12Rik", "0610011F06Rik", "0610011L14Rik", "0610012G03Rik",
"0610012H03Rik", "0610030E20Rik", "0610031J06Rik", "0610031O16Rik",
"0610037L13Rik", "0610037P05Rik", "0610038B21Rik", "0610038L08Rik",
"0610039K10Rik", "0610040B10Rik", "0610040F04Rik", "0610040J01Rik",
"0610043K17Rik", "0910001L09Rik", "100043387", "1100001G20Rik",
"1110001A16Rik", "1110001J03Rik", "1110002B05Rik", "1110002L01Rik",
"1110002N22Rik", "1110003E01Rik", "1110004E09Rik", "1110004F10Rik",
"1110005A03Rik", "1110006O24Rik", "1110007C09Rik", "1110008F13Rik",
"1110008J03Rik", "1110008L16Rik"
),
elementType = "ANY",
elementMetadata = NULL,
metadata = list()
)
),
colData = new(
"DFrame",
rownames = c(
"IM_MR30_S30_L001", "IM_MR31_S31_L001", "IM_MR32_S32_L001",
"IM_MR33_S33_L001", "IM_MR34_S34_L001", "IM_MR35_S35_L001",
"IM_MR36_S36_L001", "IM_AR_30", "IM_AR_31", "IM_AR_32", "IM_AR_33"
),
nrows = 11L,
listData = list(
batch = structure(
c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L),
.Label = c(
"190701_K00242_0579_AH7GFLBBXY",
"180810_K00242_0453_AHVJTJBBXX-IM-AR-RS21+180814_K00242_0456_AHW5LYBBXX-IM-AR-RS21+180817_K00242_0458_AHW57TBBXX-IM-AR-RS21",
"180406_K00242_0385_AHTCCHBBXX-IM-AR-RS8+180412_K00242_0388_AHT7NYBBXX-IM-AR-RS8",
"180814_K00242_0456_AHW5LYBBXX-IM-AR-RS21+180814_K00242_0456_AHW5LYBBXX-IM-AR-RS21+180817_K00242_0458_AHW57TBBXX-IM-AR-RS21",
"190322_K00242_0534_AHYLVWBBXX_IM-AM-RS8-dT"
),
class = "factor"
),
time_label = c( "D8", "D10", "D10", "D10", "D15", "D15", "D15", "D6",
"D6", "D6", "D6"
),
time_value = c(8L, 10L,
10L, 10L, 15L, 15L, 15L, 6L, 6L, 6L, 6L),
user = c("MR",
"MR", "MR", "MR", "MR", "MR", "MR", "AR", "AR", "AR",
"AR"),
treatment = structure(
c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 1L),
.Label = c("ctrl", "OE"),
class = "factor"
),
group = structure(
c(10L, 11L, 11L, 11L, 12L, 12L, 12L,
13L, 13L, 13L, 14L),
.Label = c(
"M_2i_ctrl", "M_D0_ctrl", "M_D1_ctrl", "M_D2_ctrl", "M_D3_ctrl",
"M_D4_ctrl", "M_D5_ctrl", "M_D6_ctrl", "M_D7_ctrl", "M_D8_ctrl",
"M_D10_ctrl", "M_D15_ctrl", "A_D6_OE", "A_D6_ctrl", "A_D7_ctrl",
"A_D7_OE", "A_D8_ctrl", "A_D8_OE", "A_D11_ctrl", "A_D11_OE"
),
class = "factor"
),
group_pca_label = c(
NA, "M_D10_ctrl", NA, NA, "M_D15_ctrl", NA, NA, "A_D6_OE", NA, NA,
"A_D6_ctrl"
),
condition = structure(
c(10L,
11L, 11L, 11L, 13L, 13L, 13L, 14L, 14L, 14L, 8L),
.Label = c(
"2i_ctrl", "D0_ctrl", "D1_ctrl", "D2_ctrl", "D3_ctrl", "D4_ctrl",
"D5_ctrl", "D6_ctrl", "D7_ctrl", "D8_ctrl", "D10_ctrl", "D11_ctrl",
"D15_ctrl", "D6_OE", "D7_OE", "D8_OE", "D11_OE"
),
class = "factor"
),
time = structure(
c(10L, 11L, 11L,
11L, 13L, 13L, 13L, 8L, 8L, 8L, 8L),
.Label = c(
"2i", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D10",
"D11", "D15"
),
class = "factor"
)
),
elementType = "ANY",
elementMetadata = new(
"DFrame",
rownames = NULL,
nrows = 9L,
listData = list(
type = c(
"input", "input", "input", "input", "input", "input", "input",
"input", "input"
),
description = c("",
"", "", "", "", "", "", "", "")
),
elementType = "ANY",
elementMetadata = NULL,
metadata = list()
),
metadata = list()
),
assays = new(
"SimpleAssays",
data = new(
"SimpleList",
listData = list(counts = structure(
c(
0L, 221L, 582L, 60L, 392L, 521L, 88L, 0L, 0L, 99L, 405L, 3L, 345L,
0L, 221L, 151L, 4L, 63L, 227L, 117L, 11L, 376L, 406L, 0L, 143L,
255L, 5L, 0L, 0L, 7L, 5L, 1L, 0L, 182L, 8L, 0L, 87L, 20L, 381L, 71L,
58L, 331L, 56L, 589L, 36L, 2L, 73L, 254L, 55L, 95L, 0L, 381L, 691L,
80L, 353L, 397L, 126L, 0L, 0L, 151L, 434L, 6L, 374L, 0L, 242L, 134L,
43L, 113L, 232L, 130L, 23L, 325L, 458L, 0L, 165L, 358L, 4L, 0L, 0L,
10L, 0L, 0L, 4L, 225L, 7L, 0L, 100L, 52L, 486L, 115L, 73L, 512L,
86L, 639L, 50L, 3L, 108L, 273L, 64L, 105L, 0L, 261L, 588L, 65L,
334L, 367L, 88L, 0L, 0L, 102L, 389L, 8L, 333L, 0L, 216L, 158L, 38L,
87L, 254L, 87L, 24L, 302L, 434L, 0L, 159L, 292L, 4L, 0L, 2L, 7L, 1L,
1L, 0L, 197L, 12L, 0L, 86L, 39L, 482L, 99L, 58L, 408L, 67L, 657L,
43L, 1L, 73L, 242L, 63L, 68L, 0L, 271L, 579L, 88L, 298L, 383L, 80L,
0L, 0L, 95L, 358L, 3L, 271L, 0L, 195L, 143L, 23L, 64L, 200L, 82L,
27L, 334L, 382L, 0L, 170L, 296L, 4L, 0L, 0L, 4L, 0L, 1L, 1L, 171L,
14L, 0L, 122L, 26L, 365L, 86L, 62L, 343L, 67L, 589L, 35L, 1L, 59L,
251L, 39L, 71L, 0L, 332L, 566L, 112L, 330L, 282L, 82L, 0L, 0L, 107L,
318L, 1L, 349L, 0L, 218L, 119L, 122L, 68L, 143L, 111L, 26L, 413L,
540L, 0L, 124L, 315L, 0L, 0L, 1L, 6L, 0L, 1L, 3L, 235L, 13L, 0L,
88L, 66L, 508L, 99L, 71L, 510L, 73L, 532L, 46L, 1L, 145L, 342L, 49L,
60L, 0L, 297L, 598L, 100L, 283L, 278L, 58L, 0L, 0L, 115L, 306L, 4L,
368L, 0L, 208L, 109L, 105L, 81L, 190L, 113L, 13L, 406L, 563L, 0L,
115L, 280L, 5L, 0L, 0L, 4L, 0L, 1L, 2L, 238L, 22L, 0L, 78L, 75L,
532L, 54L, 53L, 484L, 79L, 510L, 35L, 1L, 154L, 361L, 46L, 45L, 0L,
413L, 724L, 102L, 352L, 325L, 77L, 0L, 0L, 87L, 364L, 8L, 398L, 0L,
201L, 130L, 94L, 63L, 227L, 116L, 16L, 398L, 594L, 0L, 127L, 312L,
4L, 0L, 0L, 8L, 0L, 0L, 0L, 285L, 12L, 0L, 99L, 61L, 638L, 56L, 44L,
562L, 80L, 604L, 32L, 3L, 178L, 394L, 51L, 81L, 0L, 342L, 1147L,
136L, 887L, 568L, 197L, 0L, 0L, 192L, 644L, 13L, 653L, 0L, 601L,
286L, 36L, 98L, 478L, 190L, 8L, 706L, 694L, 0L, 229L, 306L, 11L, 0L,
1L, 9L, 0L, 6L, 10L, 221L, 39L, 0L, 132L, 109L, 1132L, 350L, 133L,
567L, 115L, 931L, 61L, 5L, 70L, 561L, 130L, 133L, 0L, 337L, 1162L,
135L, 927L, 578L, 182L, 0L, 0L, 242L, 665L, 21L, 702L, 0L, 674L,
307L, 35L, 122L, 475L, 176L, 8L, 653L, 714L, 0L, 251L, 312L, 11L,
0L, 3L, 15L, 0L, 9L, 10L, 209L, 31L, 0L, 168L, 111L, 1231L, 383L,
150L, 552L, 129L, 980L, 72L, 4L, 52L, 686L, 142L, 130L, 1L, 284L,
1159L, 145L, 861L, 529L, 168L, 0L, 0L, 202L, 688L, 3L, 670L, 0L,
654L, 298L, 27L, 122L, 465L, 197L, 15L, 707L, 657L, 0L, 223L, 284L,
6L, 0L, 1L, 13L, 0L, 3L, 10L, 199L, 31L, 0L, 125L, 88L, 1142L, 397L,
121L, 593L, 128L, 888L, 60L, 7L, 54L, 595L, 117L, 150L, 0L, 224L,
1228L, 68L, 894L, 674L, 213L, 0L, 0L, 197L, 798L, 12L, 758L, 0L,
446L, 285L, 21L, 75L, 458L, 185L, 5L, 738L, 456L, 0L, 261L, 339L,
7L, 0L, 0L, 9L, 0L, 0L, 1L, 180L, 32L, 0L, 110L, 98L, 919L, 249L,
134L, 387L, 188L, 1055L, 64L, 3L, 52L, 630L, 110L, 175L
),
.Dim = c(50L, 11L),
.Dimnames = list(
c(
"0610005C13Rik", "0610007C21Rik", "0610007L01Rik",
"0610007N19Rik", "0610007P08Rik", "0610007P14Rik",
"0610007P22Rik", "0610008F07Rik", "0610009B14Rik",
"0610009B22Rik", "0610009D07Rik", "0610009L18Rik",
"0610009O20Rik", "0610010B08Rik", "0610010F05Rik",
"0610010K14Rik", "0610010O12Rik", "0610011F06Rik",
"0610011L14Rik", "0610012G03Rik", "0610012H03Rik",
"0610030E20Rik", "0610031J06Rik", "0610031O16Rik",
"0610037L13Rik", "0610037P05Rik", "0610038B21Rik",
"0610038L08Rik", "0610039K10Rik", "0610040B10Rik",
"0610040F04Rik", "0610040J01Rik", "0610043K17Rik",
"0910001L09Rik", "100043387", "1100001G20Rik", "1110001A16Rik",
"1110001J03Rik", "1110002B05Rik", "1110002L01Rik",
"1110002N22Rik", "1110003E01Rik", "1110004E09Rik",
"1110004F10Rik", "1110005A03Rik", "1110006O24Rik",
"1110007C09Rik", "1110008F13Rik", "1110008J03Rik", "1110008L16Rik"
),
c(
"IM_MR30_S30_L001", "IM_MR31_S31_L001", "IM_MR32_S32_L001",
"IM_MR33_S33_L001", "IM_MR34_S34_L001", "IM_MR35_S35_L001",
"IM_MR36_S36_L001", "IM_AR_30", "IM_AR_31", "IM_AR_32", "IM_AR_33"
)
)
)),
elementType = "ANY",
elementMetadata = NULL,
metadata = list()
)
),
NAMES = NULL,
elementMetadata = new(
"DFrame",
rownames = NULL,
nrows = 50L,
listData = structure(list(), .Names = character(0)),
elementType = "ANY",
elementMetadata = NULL,
metadata = list()
),
metadata = list(version = structure(
list(c(1L, 30L, 1L)), class = c("package_version",
"numeric_version")
))
)
We can use
data_bec <- dds_tmp %>%
{sva::ComBat_seq(
counts = {.} %>% SummarizedExperiment::assay(),
batch = {.} %>% magrittr::extract2("batch") %>% droplevels(),
covar_mod = cbind(
time = {.} %>% magrittr::extract2("time") %>% droplevels(),
treatment = {.} %>% magrittr::extract2("treatment") %>% droplevels()
)
)}
I am trying to make a simple barplot with the data shown below
xx <- structure(list(13L, 65L, 569L, 452L, 7L, 11L, 58L, 134L, 18L,
17L, 4L, 18L, 93L, 0L, 0L, 2L, 1L, 50L, 135L, 7L, 88L, 226L,
179L, 0L, 0L, 44L, 121L, 17L, 191L, 1L), .Dim = 5:6, .Dimnames = list(
c("minus_2_H", "minus_H", "no_adduct", "plus_H", "plus_2H"
), c("a", "b", "c", "x", "y", "z")))
however it only works for the
barplot (xx)
and fails with
barplot (xx, beside = TRUE)
Error in -0.01 * height : non-numeric argument to binary operator
Could anyone clarify why its complaining even though the matrix is numeric in both cases?
So I have R program, and am struggling with getting all points in map
library(ggmap)
library(ggplot2)
setwd("d:/GIS/")
sep <- read.csv("SEP_assets_csv.csv")
Sub1 <- sep[grep("SEP.12", names(sep))]
sep$newCol <- 100*rowSums(Sub1)/rowSums(sep[4:7])
# create a new grouping variable
Percent_SEP12_Assets <- ifelse(sep[,8] >= 50, "Over 50", "Under 50")
# get the map
map <- get_map("Kissena Park, Queens", zoom = 13, maptype = 'roadmap')
# plot the map and use the grouping variable for the fill inside the aes
ggmap(map) +
geom_point(data=sep, aes(x = Longitude, y = Latitude, color=Percent_SEP12_Assets ), size=9, alpha=0.6) +
scale_color_manual(breaks=c("Over 50", "Under 50"), values=c("green","red"))
And here is output map
I wish to zoom in enough without cutting out data points, but no matter location I pick on map, the data keeps getting cut, i.e. Removed 2 rows containing missing values (geom_point).
Is there a way to set boundaries based on the extremities of latitude and longitude? The csv I import at
sep <- read.csv("SEP_assets_csv.csv")
Has list of latitude and longitude.
Help!
Coordinates
Latitude Longitude
40.758365 -73.824407
40.774168 -73.818543
40.761748 -73.811379
40.765602 -73.828293
40.751762 -73.81778
40.764834 -73.789712
40.777951 -73.842932
40.76501 -73.794319
40.785959 -73.817349
40.755764 -73.799256
40.745593 -73.829283
40.789929 -73.839501
40.760072 -73.783908
40.726437 -73.807592
40.741093 -73.808757
40.720926 -73.823358
40.729642 -73.81781
40.724191 -73.80937
40.782346 -73.77844
40.778164 -73.799841
40.775122 -73.8185
40.760344 -73.817909
40.792326 -73.809516
40.78322 -73.806977
40.73106 -73.805449
40.736521 -73.813001
40.783714 -73.795027
40.770194 -73.82762
40.735855 -73.823583
40.74943 -73.82141
40.769753 -73.832001
40.754465 -73.826204
40.738775 -73.823892
40.764868 -73.826819
40.738332 -73.82028
40.735017 -73.821339
40.72535 -73.811325
40.721466 -73.820401
dput
> dput(sep)
structure(list(School = structure(1:38, .Label = c("Queens\\25Q020",
"Queens\\25Q021", "Queens\\25Q022", "Queens\\25Q023", "Queens\\25Q024",
"Queens\\25Q025", "Queens\\25Q029", "Queens\\25Q032", "Queens\\25Q079",
"Queens\\25Q107", "Queens\\25Q120", "Queens\\25Q129", "Queens\\25Q130",
"Queens\\25Q154", "Queens\\25Q163", "Queens\\25Q164", "Queens\\25Q165",
"Queens\\25Q168", "Queens\\25Q169", "Queens\\25Q184", "Queens\\25Q185",
"Queens\\25Q189", "Queens\\25Q193", "Queens\\25Q194", "Queens\\25Q200",
"Queens\\25Q201", "Queens\\25Q209", "Queens\\25Q214", "Queens\\25Q219",
"Queens\\25Q237", "Queens\\25Q242", "Queens\\25Q244", "Queens\\25Q425",
"Queens\\25Q460", "Queens\\25Q499", "Queens\\25Q515", "Queens\\25Q707",
"Queens\\25Q792"), class = "factor"), Latitude = c(40.758365,
40.774168, 40.761748, 40.765602, 40.751762, 40.764834, 40.777951,
40.76501, 40.785959, 40.755764, 40.745593, 40.789929, 40.760072,
40.726437, 40.741093, 40.720926, 40.729642, 40.724191, 40.782346,
40.778164, 40.775122, 40.760344, 40.792326, 40.78322, 40.73106,
40.736521, 40.783714, 40.770194, 40.735855, 40.74943, 40.769753,
40.754465, 40.738775, 40.764868, 40.738332, 40.735017, 40.72535,
40.721466), Longitude = c(-73.824407, -73.818543, -73.811379,
-73.828293, -73.81778, -73.789712, -73.842932, -73.794319, -73.817349,
-73.799256, -73.829283, -73.839501, -73.783908, -73.807592, -73.808757,
-73.823358, -73.81781, -73.80937, -73.77844, -73.799841, -73.8185,
-73.817909, -73.809516, -73.806977, -73.805449, -73.813001, -73.795027,
-73.82762, -73.823583, -73.82141, -73.832001, -73.826204, -73.823892,
-73.826819, -73.82028, -73.821339, -73.811325, -73.820401), Windows.SEP.11 = c(48L,
154L, 11L, 62L, 20L, 72L, 9L, 37L, 8L, 22L, 9L, 47L, 44L, 99L,
78L, 91L, 42L, 122L, 55L, 14L, 162L, 108L, 89L, 87L, 23L, 14L,
75L, 74L, 141L, 73L, 43L, 14L, 534L, 189L, 128L, 10L, 79L, 38L
), Mac.SEP.11 = c(49L, 0L, 180L, 2L, 202L, 116L, 41L, 1L, 17L,
22L, 33L, 43L, 1L, 28L, 2L, 0L, 238L, 13L, 76L, 55L, 76L, 42L,
0L, 1L, 12L, 0L, 16L, 10L, 1L, 7L, 0L, 1L, 1L, 67L, 16L, 7L,
31L, 24L), Windows.SEP.12 = c(52L, 252L, 1L, 2L, 12L, 45L, 108L,
15L, 14L, 4L, 19L, 21L, 46L, 90L, 10L, 86L, 15L, 76L, 122L, 2L,
9L, 52L, 39L, 120L, 43L, 17L, 9L, 54L, 19L, 199L, 40L, 25L, 64L,
164L, 14L, 27L, 45L, 2L), Mac.SEP.12 = c(73L, 2L, 91L, 53L, 288L,
6L, 2L, 107L, 109L, 97L, 41L, 18L, 12L, 16L, 2L, 2L, 270L, 32L,
45L, 92L, 54L, 190L, 1L, 4L, 19L, 53L, 1L, 10L, 0L, 61L, 50L,
27L, 27L, 25L, 3L, 1L, 43L, 0L), newCol = c(56.3063063063063,
62.2549019607843, 32.5088339222615, 46.218487394958, 57.4712643678161,
21.3389121338912, 68.75, 76.25, 83.1081081081081, 69.6551724137931,
58.8235294117647, 30.2325581395349, 56.3106796116505, 45.4935622317597,
13.0434782608696, 49.1620111731844, 50.4424778761062, 44.4444444444444,
56.0402684563758, 57.6687116564417, 20.9302325581395, 61.734693877551,
31.0077519379845, 58.4905660377358, 63.9175257731959, 83.3333333333333,
9.9009900990099, 43.2432432432432, 11.8012422360248, 76.4705882352941,
67.6691729323308, 77.6119402985075, 14.5367412140575, 42.4719101123596,
10.5590062111801, 62.2222222222222, 44.4444444444444, 3.125)), .Names = c("School",
"Latitude", "Longitude", "Windows.SEP.11", "Mac.SEP.11", "Windows.SEP.12",
"Mac.SEP.12", "newCol"), row.names = c(NA, -38L), class = "data.frame")
You haven't provided us with any of the data, so I'm going to give an example using a dataset in the historydata package. Instead of getting a map based on a location and a zoom, you can get a map based on the bounding box of the latitudes and longitudes in your dataset.
library(historydata)
library(ggmap)
data("catholic_dioceses")
bbox <- make_bbox(catholic_dioceses$long, catholic_dioceses$lat, f = 0.01)
map <- get_map(bbox)
ggmap(map) +
geom_point(data=catholic_dioceses, aes(x = long, y = lat))
Note that the f = argument to make_bbox() lets you control how much padding there is around your map.
In your case, I think this will work:
library(ggmap)
bbox <- make_bbox(sep$Longitude, sep$Latitude, f = 0.01)
map <- get_map(bbox)
ggmap(map) +
geom_point(data=sep, aes(x = Longitude, y = Latitude,
color = Percent_SEP12_Assets),
size = 9, alpha = 0.6) +
scale_color_manual(breaks=c("Over 50", "Under 50"), values=c("green","red"))