Related
Im trying to add a heatmap to my phylogenetic tree. The range of the heatmap should be from 0 to 100 instead it only covers the the min and max of the values. Can I reset the range of the heatmap?
thanks.
library(ggtree)
library(ggplot2)
library(ggstance)
df1 <- structure(
list(id = structure(
c(5L, 15L, 29L, 18L, 24L, 21L,
13L, 11L, 8L, 25L, 23L, 9L, 16L, 3L, 6L, 2L, 20L, 27L, 30L, 17L,
14L, 4L, 1L, 7L, 22L, 28L, 10L, 12L, 26L, 19L),
.Label = c("t1",
"t10", "t11", "t12", "t13", "t14", "t15", "t16", "t17", "t18",
"t19", "t2", "t20", "t21", "t22", "t23", "t24", "t25", "t26",
"t27", "t28", "t29", "t3", "t30", "t4", "t5", "t6", "t7", "t8",
"t9"), class = "factor"),
location = structure(c(1L, 3L, 2L,
1L, 2L, 3L, 3L, 2L, 3L, 2L, 3L, 3L, 2L, 2L, 1L, 1L, 3L, 2L, 1L,
1L, 3L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 1L, 1L),
.Label = c("CZ", "GZ", "HK"), class = "factor"),
Value = c(22L, 10L, 33L, 12L, NA,
NA, NA, NA, NA, NA, NA, NA, 45L, 89L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 80L, NA, NA, NA, NA)),
class = "data.frame", row.names = c(NA,
-30L))
tr <- rtree(30)
p <- ggtree(tr)
#df1<- your_example_data
p1 <- p %<+% df1 + geom_tippoint(aes(color=location))+ guides(color = "none")
d2 <- data.frame( val=rnorm(30, mean= 50, sd=20))
rownames(d2)<- tr$tip.label
library(ggnewscale)
p1 <- p1 + new_scale_fill()
p2<- gheatmap(p1, d2 ,offset=0.015, width=0.05,
colnames_angle=45, colnames_offset_y = 0.25,colnames_offset_x =0.001, colnames=TRUE,
colnames_position='top',font.size = 3)+
scale_fill_viridis_c(option="A", name="query\ncoverage\npercentage")
p2
Try using scale_fill_gradientn. I don't have ggtree in my library collection, but it should work with it too. data$Z are the values used in the legend.
min(data$Z)
[1] 10.43507
# using geom_tile instead
ggplot(data, aes(X, Y, fill= Z)) +
geom_tile() +
scale_fill_gradientn(limits = c(0,max(data$Z)),
colours=viridis(10,o="A"),
breaks=c(0,max(data$Z)),
labels=c(0,max(data$Z)))
Data
data <- structure(list(X = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L), .Label = c("A", "B", "C", "D", "E", "F", "G", "H",
"I", "J"), class = "factor"), Y = structure(c(1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L), .Label = c("var1", "var2", "var3", "var4", "var5",
"var6", "var7", "var8", "var9", "var10"), class = "factor"),
Z = c(33.991562910378, 35.5263787321746, 24.5632742531598,
18.0254957079887, 45.778294513002, 38.0070783570409, 38.8778781332076,
13.9182714093477, 13.2864724285901, 12.3245238792151, 45.4634746629745,
43.5207717958838, 14.6174691990018, 14.6395265311003, 16.3748204801232,
37.5898649636656, 46.154183940962, 21.7670671269298, 45.9928634669632,
15.2300526481122, 42.3459290526807, 36.1509132292122, 13.004608694464,
17.2632187511772, 24.1008642502129, 21.0504860430956, 47.8412099648267,
22.8905160259455, 26.2689692527056, 42.2642367053777, 49.7228981740773,
18.5286565497518, 19.9640860501677, 19.8192273359746, 46.2587429210544,
45.3112288471311, 14.0251182205975, 46.5721819829196, 19.2603973485529,
11.8241156637669, 43.5814412590116, 12.3338401783258, 34.6708638872951,
16.535308547318, 12.5870429351926, 17.7716215513647, 38.3571200724691,
40.5572446156293, 38.3018106594682, 36.1261784471571, 23.6329158209264,
38.2715854980052, 31.8956978339702, 19.8036628682166, 41.236245688051,
42.5284101255238, 47.3572976142168, 10.9305525757372, 41.5727174282074,
39.237065333873, 41.6476187948138, 43.6902561411262, 39.2061061505228,
18.3187866955996, 42.8791201952845, 33.8544269837439, 17.3525733780116,
14.5423825085163, 46.209614733234, 24.5643785689026, 35.3784507885575,
44.3101883865893, 45.7905176281929, 36.0531417001039, 44.190902383998,
32.4274326208979, 33.8546730671078, 43.7150628026575, 44.4308217708021,
27.6862936094403, 39.8551124054939, 10.4350713547319, 35.6894047465175,
28.6168400477618, 18.5768875014037, 17.1367645263672, 30.369380293414,
17.7864238992333, 36.1986118741333, 43.2466325163841, 49.581032032147,
49.736803509295, 40.3205085452646, 27.0655540842563, 42.9749015253037,
30.9310132544488, 23.7332978192717, 35.1737863756716, 40.4224442131817,
15.6103290617466)), out.attrs = list(dim = c(X = 10L, Y = 10L
), dimnames = list(X = c("X=A", "X=B", "X=C", "X=D", "X=E", "X=F",
"X=G", "X=H", "X=I", "X=J"), Y = c("Y=var1", "Y=var2", "Y=var3",
"Y=var4", "Y=var5", "Y=var6", "Y=var7", "Y=var8", "Y=var9", "Y=var10"
))), row.names = c(NA, -100L), class = "data.frame")
I would like to please organise the following plots so that facets are printed out from most to least busy (i.e. Hemiptera, Coleoptera, Hymenoptera, Siphonaptera, Lepidoptera, etc.)
I would also like to order the levels within each facet like in Coleoptera. I realise that the X-labels will change order too so I need each facet to print out its own X-label according the level order.
I have already read many threads and that's how I was able to organise Coleoptera. But now I want it to be more tidy.
This is the data (let me know if this format is ok, if not I can try another way):
structure(list(Order = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L), .Label = c("Coleoptera",
"Dermaptera", "Dictyoptera", "Diptera", "Hemiptera", "Hymenoptera",
"Lepidoptera", "Phthiraptera", "Psocoptera", "Siphonaptera",
"Thysanoptera"), class = "factor"), Nrange = structure(c(1L,
3L, 4L, 5L, 6L, 7L, 8L, 10L, 11L, 12L, 14L, 14L, 1L, 10L, 1L,
3L, 4L, 6L, 7L, 10L, 11L, 12L, 14L, NA, 1L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 14L, NA, 1L, 4L, 5L, 6L, 7L, 8L, 10L, 11L,
12L, 14L, 15L, NA, 1L, 2L, 4L, 5L, 6L, 7L, 8L, 10L, 11L, 12L,
13L, 14L, 4L, 10L, 11L, 12L, 14L, 1L, 4L, 10L, 11L, 12L, 13L,
14L, 1L, 5L, 10L, 1L, 4L, 6L, 7L, 10L, 11L, 12L, 14L), .Label = c("Africa",
"Africa, Asia", "Americas", "Asia", "Asia-Temp", "Asia-Trop",
"Australasia", "C&S America", "Cosmopolitan", "Cryptogenic",
"N America", "S America", "Trop", "Trop, SubTrop", "Unknown"), class = "factor"),
Records = c(16L, 1L, 9L, 7L, 11L, 17L, 1L, 15L, 8L, 8L, 5L,
1L, 2L, 1L, 5L, 1L, 1L, 1L, 1L, 9L, 9L, 2L, 1L, 4L, 11L,
10L, 30L, 15L, 9L, 2L, 2L, 2L, 34L, 11L, 21L, 1L, 21L, 16L,
8L, 1L, 14L, 3L, 5L, 25L, 4L, 2L, 1L, 1L, 8L, 1L, 10L, 1L,
2L, 1L, 1L, 8L, 5L, 2L, 1L, 2L, 2L, 9L, 1L, 2L, 1L, 3L, 1L,
12L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 1L, 1L, 1L, 1L, 3L,
3L, 2L)), .Names = c("Order", "Nrange", "Records"), row.names = c(NA,
-83L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = "Order", drop = TRUE)
This is the reordering that I guess is affecting only Coleoptera.
xy<-x%>%
mutate(Nrange=reorder(Nrange,-Records,sum))
This is the plot:
to_plot<-xy %>%
filter(!is.na(Nrange))
ggplot(to_plot,aes(x=Nrange,y=Records,fill=Nrange))+
geom_col()+
theme(axis.text.x = element_text(angle=90, vjust=0.7), legend.position = "none") +
facet_wrap(~Order,ncol=3)+
labs(title="Insects recorded as alien-invasive to mainland Spain",
subtitle="Native ranges vs number of records",
caption="Data source: DAISIE (http://www.europe-aliens.org/)")
And this is the plot:
enter image description here
Assuming you're using the tidyverse (based on your code):
library(tidyverse)
xy <- x %>%
ungroup() %>%
mutate(
Order = fct_reorder(Order, Records, sum, .desc = TRUE)
)
xy %>%
filter(!is.na(Nrange)) %>%
ggplot() +
aes(x = Nrange, y = Records, fill = Nrange) +
geom_col() +
facet_wrap(~Order, ncol = 3)
fct_reorder comes from the forcats package, which I believe is now a part of the tidyverse.
Or, using base R, something like this:
xy <- x
record_sums <- tapply(xy$Records, xy$Order, sum)
levels(xy$Order) <- levels(xy$Order)[order(record_sums, decreasing = TRUE)]
I am new to R and trying to figure out a way to plot means for individual samples as well as group means with ggplot.
I am following this articles on R-bloggers (last paragraph):
https://www.r-bloggers.com/plotting-individual-observations-and-group-means-with-ggplot2/
This is my code:
gd <- meanplot1 %>%
group_by(treatment, value) %>%
summarise(measurement = mean(measurement))
ggplot(meanplot1, aes(x=value, y=measurement, color=treatment)) +
geom_line(aes(group=sample), alpha=0.3) +
geom_line(data=gd, size=3, alpha=0.9) +
theme_bw()
Whilst the sample means are being shown, the group means arenĀ“t. I get the error
geom_path: Each group consists of only one observation. Do you need
to adjust the group aesthetic?
Upon adding group=1, I get a weirdly mixed category mean, but not what I am looking for..
I scrolled through a lot of articles already, but couldnt find an answer - I would be so happy if somebody could help me out here!! :)
My data (meanplot1) is formatted like this:
treatment sample value measurement
1 control, control 1, initial, 20,
2 control, control 1, 26, NA,
3 control, control 1, 26', 28,
12 control, control 2, initial, 22,
13 control control 2, 26, NA,
14 control control 2, 26', 36,
15 control control 2, 28, 45,
67 stressed, stress 1, initial, 37,
68 stressed, stress 1, 26, NA,
69 stressed, stress 1, 26', 17,
78 stressed, stress 2, initial, 36,
79 stressed, stress 2, 26, NA,
80 stressed, stress 2, 26', 25,
I am hoping to see 6 lines, one mean for stress 1, stress 2, control 1 and control 2, and one mean for all treatment=control, and one for all treatment=stressed
output dput(gd):
structure(list(treatment = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
), .Label = c("control", "stressed"), class = "factor"), value = structure(c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L), .Label = c("26", "26'", "28", "28'",
"30", "30'", "32", "32'", "34", "34'", "initial"), class = "factor"),
measurement = c(NA, 32.3333333333333, 39.5, 30.3333333333333,
31.8333333333333, 31.8333333333333, NA, 36, 34.6666666666667,
36, 24.6666666666667, NA, 25.3333333333333, 33.3333333333333,
32, 50.1666666666667, 39.1666666666667, NA, 33.5, 24.3333333333333,
27.3333333333333, 36)), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"), row.names = c(NA, -22L), vars = list(treatment), drop = TRUE, .Names = c("treatment",
"value", "measurement"))
output dput(meanplot1):
structure(list(treatment = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("control",
"stressed"), class = "factor"), sample = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L), .Label = c("control 1",
"control 2", "control 3", "control 4", "control 5", "control 6",
"stress 1", "stress 2", "stress 3", "stress 4", "stress 5", "stress 6"
), class = "factor"), value = structure(c(11L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L), .Label = c("26", "26'",
"28", "28'", "30", "30'", "32", "32'", "34", "34'", "initial"
), class = "factor"), measurement = c(20L, NA, 28L, 18L, 17L,
19L, 34L, NA, 23L, 29L, 27L, 22L, NA, 36L, 45L, 31L, 40L, 44L,
NA, 49L, 40L, 39L, 32L, NA, 35L, 57L, 30L, 37L, 29L, NA, 44L,
37L, 46L, 20L, NA, 39L, 27L, 30L, 40L, 25L, NA, 29L, 50L, 30L,
26L, NA, 28L, 45L, 47L, 27L, 35L, NA, 24L, 22L, 35L, 28L, NA,
28L, 45L, 27L, 28L, 24L, NA, 47L, 30L, 39L, 37L, NA, 17L, 29L,
29L, 31L, 29L, NA, 37L, 21L, 27L, 36L, NA, 25L, 41L, 51L, 66L,
50L, NA, 33L, 25L, 22L, 36L, NA, 33L, 45L, 26L, 72L, 59L, NA,
33L, 26L, 25L, 33L, NA, 21L, 33L, 25L, 29L, 21L, NA, 26L, 20L,
16L, 22L, NA, 30L, 27L, 28L, 57L, 41L, NA, 28L, 23L, 17L, 52L,
NA, 26L, 25L, 33L, 46L, 35L, NA, 44L, 31L, 57L)), .Names = c("treatment",
"sample", "value", "measurement"), class = "data.frame", row.names = c(NA,
-132L))
I suppose you are aiming to plot the treatment means.
By default, since you are using a categorical x-axis, the grouping is set to the interaction between x and color. You only want to group by treatment, however. So we'll add the correct grouping to the call.
ggplot(meanplot1, aes(x = value, y = measurement, color=treatment)) +
geom_line(aes(group=sample), alpha=0.3) +
geom_line(aes(group = treatment), gd, size=3, alpha=0.9) +
theme_bw()
Also note that
ggplot(meanplot1, aes(x=value, y=measurement, color=treatment)) +
geom_line(aes(group=sample), alpha=0.3) +
stat_summary(aes(group = treatment), fun.y = mean, geom = 'line', size=3, alpha=0.9) +
theme_bw()
Gives the same plot, without the interruption.
I am using systemfit to run system of equations using SUR method. I need to read long (multiple line) formula.My simple reproducible dataset can be accessed using following codes.
dat<-structure(list(Time = structure(c(9L, 7L, 15L, 1L, 17L, 13L,
11L, 3L, 23L, 21L, 19L, 5L, 10L, 8L, 16L, 2L, 18L, 14L, 12L,
4L, 24L, 22L, 20L, 6L), .Label = c("Apr-00", "Apr-01", "Aug-00",
"Aug-01", "Dec-00", "Dec-01", "Feb-00", "Feb-01", "Jan-00", "Jan-01",
"Jul-00", "Jul-01", "Jun-00", "Jun-01", "Mar-00", "Mar-01", "May-00",
"May-01", "Nov-00", "Nov-01", "Oct-00", "Oct-01", "Sep-00", "Sep-01"
), class = "factor"), ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L), .Label = c("A", "B"), class = "factor"), y1 = c(25L,
14L, 45L, 15L, 24L, 17L, 18L, 19L, 14L, 15L, 25L, 14L, 45L, 15L,
24L, 17L, 18L, 19L, 14L, 15L, 25L, 14L, 45L, 15L), y2 = c(4L,
3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L, 4L, 3L, 4L, 5L, 1L,
4L, 5L, 3L, 6L, 4L, 2L, 5L), x1 = c(3L, 4L, 1L, 8L, 6L, 7L, 9L,
7L, 3L, 1L, 2L, 5L, 6L, 3L, 4L, 1L, 8L, 6L, 7L, 9L, 7L, 3L, 1L,
2L), x2 = c(4L, 3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L, 4L,
3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L), x3 = c(3L, 4L, 2L,
8L, 6L, 7L, 9L, 7L, 3L, 1L, 2L, 5L, 6L, 3L, 4L, 2L, 8L, 6L, 7L,
9L, 7L, 3L, 1L, 2L), x4 = c(4L, 3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L,
4L, 2L, 5L, 4L, 3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L),
x5 = c(3L, 4L, 3L, 8L, 6L, 7L, 9L, 7L, 3L, 1L, 2L, 5L, 6L,
3L, 4L, 3L, 8L, 6L, 7L, 9L, 7L, 3L, 1L, 2L)), .Names = c("Time",
"ID", "y1", "y2", "x1", "x2", "x3", "x4", "x5"), class = "data.frame", row.names = c(NA,
-24L))
My example formula is like this,
model1<- y1 ~ x1 + x2 + x3
+ x4 +x5
eqSystem <- list(model1)
library(systemfit)
fit_prod_SUR <- systemfit(eqSystem, method= "SUR", data=dat)
print(fit_prod_SUR)
I have to include several very long formulas into eqSystem. But my problem is since my formula (e.g. model1) are very long it has got multiple lines. When I run the eqSystem with systemfit, it reads only the variables in the very first line of each formula. I tried with following code, but it does not work.
model1<- (get(paste("y1 ~ x1 + x2 + x3",
" + x4 + x5", sep="")))
But it does not take as a formula. Please could anyone help me to how to read all variables (in multiple lines) of formula in R.
So i have the following for loop:
for (Count in 1:19){
png(paste0(colnames(fdd$rawCounts)[Count], ".pdf"))
qplot(y = log2(fdd$rawCounts[,Count]), main = colnames(fdd$rawCounts)[Count])
dev.off()
}
Which should simply plot some count data which i put a head from here:
structure(c(11L, 3L, 12L, 8L, 15L, 2L, 5L, 2L, 8L, 7L, 6L, 10L,
6L, 1L, 7L, 4L, 2L, 1L, 3L, 0L, 4L, 4L, 2L, 5L, 8L, 0L, 13L,
4L, 10L, 7L, 2L, 1L, 2L, 4L, 7L, 7L, 14L, 4L, 25L, 17L, 14L,
16L, 4L, 2L, 5L, 5L, 5L, 2L, 9L, 5L, 11L, 8L, 1L, 4L, 10L, 8L,
8L, 7L, 9L, 5L, 9L, 15L, 14L, 11L, 16L, 8L, 11L, 4L, 3L, 6L,
3L, 0L, 6L, 3L, 4L, 6L, 1L, 4L, 11L, 11L, 12L, 6L, 2L, 6L, 7L,
9L, 22L, 8L, 13L, 7L, 6L, 1L, 4L, 5L, 6L, 2L, 4L, 2L, 6L, 7L,
3L, 2L, 6L, 3L, 3L, 2L, 5L, 5L, 9L, 2L, 6L, 5L, 4L, 2L), .Dim = c(6L,
19L), .Dimnames = structure(list(feature = c("chr10:100000001-100000500",
"chr10:10000001-10000500", "chr10:1000001-1000500", "chr10:100000501-100001000",
"chr10:100001-100500", "chr10:100001001-100001500"), sample = c("K562_FAIRE_Acla_4hr_1",
"K562_FAIRE_Acla_4hr_2", "K562_FAIRE_Daun_4hr_1", "K562_FAIRE_Daun_4hr_2",
"K562_FAIRE_Etop_4hr_1", "K562_FAIRE_Etop_4hr_2", "K562_FAIRE_untreated",
"FAIRE.seq_K562_2MethylDoxo_A", "FAIRE.seq_K562_2MethylDoxo_B",
"FAIRE.seq_K562_Ctr_A", "FAIRE.seq_K562_Ctr_B", "FAIRE.seq_K562_Doxo_10uM_4hrs_A",
"FAIRE.seq_K562_Doxo_10uM_4hrs_B", "FAIRE.seq_K562_Epirubicin_A",
"FAIRE.seq_K562_Epirubicin_B", "FAIRE.seq_K562_MTX_40uM_4hrs_A",
"FAIRE.seq_K562_MTX_40uM_4hrs_B", "FAIRE.seq_K562_MTX_5uM_4hrs_A",
"FAIRE.seq_K562_MTX_5uM_4hrs_B")), .Names = c("feature", "sample"
)))
Now if i try to plot the data it gives me a variable called Count and the value is 19L. While i expect 19 plots to be drawn. Why is this happening?
Thanks!
This works for me:
for (Count in 1:19){
pdf(paste0(colnames(df)[Count], ".pdf"))
print(qplot(y = log2(df[, Count]), main = colnames(df)[Count]))
dev.off()
}
A couple of changes:
I read in your data as df. It turns out to be a matrix, so I adjusted the subsetting accordingly.
I also wrapped the qplot function in a print function which forces the figure to be created.
Finally, I switched the png function to pdf as that seemed like the files you were trying to create based on the paste0 result.