r

Transposing a data frame

℡╲_俬逩灬. 提交于 2021-02-16 13:46:44
问题 I am trying to transpose a data frame in R, but having very little luck. The data frame contains an epigenetic data set, with 300,000+ CpG sites in the first column. The 74 additional columns are split between the control and experimental groups (cancer = 69, normal = 5). I have converted the data frame into a matrix so I can transpose the data and convert it back to numerical values. However, every time I try to convert the data back to a data frame, it ends up as a list. I'm attempting to

Trim a string to a specific number of characters in R

大兔子大兔子 提交于 2021-02-16 13:46:09
问题 I would like to trim a character vector to the first five characters in each element. In this example I would like to trim each number in string to the first five characters. I am sure there must be an easy way to do this. string<- c("3243423", "23423", "34243234", "2342", "32544532", "85678657") I would like to have a a vector c("32434", "23423", "34243", "2342", "32544", "85678") 回答1: The following works as well (didn't know about strtrim ) substring(string, 1, 5) 回答2: Figured it out. Hope

Large .img file processing in R (GIS)

扶醉桌前 提交于 2021-02-16 13:44:07
问题 I am working with U.S. National Landcover Dataset (NLCD) to classify habitat type at more than 150 sites across the northeast U.S. The dataset is very large (15GB) so I cannot upload it here, but it comes in .img format at 30m resolution. I have GPS coordinates for the center point of all the sites. I would like to be able to extract the proportion of landcover classes in a 1 square kilometer around the point. My questions are: 1) How do I upload .img files into r? 2) How do I extract the

Find length of overlap in strings [closed]

心不动则不痛 提交于 2021-02-16 13:40:33
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Improve this question do you know any ready-to-use method to obtain length and also overlap of two strings? However only with R , maybe something from stringr ? I was looking here, unfortunately without succes. str1 <- 'ABCDE' str2 <- 'CDEFG' str_overlap(str1, str2) 'CDE' str_overlap

How do I use color in a geom_dotplot?

天涯浪子 提交于 2021-02-16 13:30:39
问题 I have this dotplot: ggplot(mpg, aes(drv, hwy)) + geom_dotplot(binwidth = 1, binaxis = 'y', stackdir = 'center') which renders as I want to color the dots by manufacturer. If I add a fill aesthetic: ggplot(mpg, aes(drv, hwy, fill = manufacturer)) + geom_dotplot(binwidth = 1, binaxis = 'y', stackdir = 'center') it renders as It looks like adding color has defeated the stacking algorithm somehow, causing the dots to overlap. How do I fix this? 回答1: This is the closest I've gotten: ggplot(mpg,

How do I use color in a geom_dotplot?

给你一囗甜甜゛ 提交于 2021-02-16 13:30:08
问题 I have this dotplot: ggplot(mpg, aes(drv, hwy)) + geom_dotplot(binwidth = 1, binaxis = 'y', stackdir = 'center') which renders as I want to color the dots by manufacturer. If I add a fill aesthetic: ggplot(mpg, aes(drv, hwy, fill = manufacturer)) + geom_dotplot(binwidth = 1, binaxis = 'y', stackdir = 'center') it renders as It looks like adding color has defeated the stacking algorithm somehow, causing the dots to overlap. How do I fix this? 回答1: This is the closest I've gotten: ggplot(mpg,

add_trace in Plotly in a loop [duplicate]

强颜欢笑 提交于 2021-02-16 13:25:11
问题 This question already has an answer here : Building plotly graph in for loop not displaying all series (1 answer) Closed 3 years ago . I want to plot multiple traces in a loop without overwriting all previous traces. In this post from 2015, a solution to adding traces within a loop is presented, by setting evaluate = TRUE in the plot_ly or add_trace functions. However, as of 2017 in the newer version of plot_ly, evaluate isn't an attribute. 'scatter3d' objects don't have these attributes:

add_trace in Plotly in a loop [duplicate]

谁说我不能喝 提交于 2021-02-16 13:24:27
问题 This question already has an answer here : Building plotly graph in for loop not displaying all series (1 answer) Closed 3 years ago . I want to plot multiple traces in a loop without overwriting all previous traces. In this post from 2015, a solution to adding traces within a loop is presented, by setting evaluate = TRUE in the plot_ly or add_trace functions. However, as of 2017 in the newer version of plot_ly, evaluate isn't an attribute. 'scatter3d' objects don't have these attributes:

scale_fill_manual is not working in geom_bar

让人想犯罪 __ 提交于 2021-02-16 13:15:14
问题 I'm trying to change the color in a barplot in ggplot2 using scale_fill_manual, but for some reason only works if i use the fill option inside aesthetics. I made an example: library(ggplot2) library(dplyr) iris %>% ggplot(aes(x=Sepal.Width,y=Sepal.Length))+ geom_bar(stat="identity") + scale_fill_manual(values='lightblue') Here is the result, no changing in the color: Now, using the fill option inside aesthetics, it works: iris %>% ggplot(aes(x=Sepal.Width,y=Sepal.Length, fill=factor(2) ))+

scale_fill_manual is not working in geom_bar

柔情痞子 提交于 2021-02-16 13:15:09
问题 I'm trying to change the color in a barplot in ggplot2 using scale_fill_manual, but for some reason only works if i use the fill option inside aesthetics. I made an example: library(ggplot2) library(dplyr) iris %>% ggplot(aes(x=Sepal.Width,y=Sepal.Length))+ geom_bar(stat="identity") + scale_fill_manual(values='lightblue') Here is the result, no changing in the color: Now, using the fill option inside aesthetics, it works: iris %>% ggplot(aes(x=Sepal.Width,y=Sepal.Length, fill=factor(2) ))+