r

Use xpathSApply in R

偶尔善良 提交于 2021-02-19 08:00:36
问题 I would like to get the information of href from below. http://www.mitbbs.com/bbsdoc1/USANews_101_0.html I prefer to get someting from each topic like this /USANews/31587637.html /USANews/31587633.html /USANews/31587631.html ... The code is used below, but it doesn't work. library("XML") library("httr") library("stringr") data <- list() for( i in 101:201){ url <- paste('bbsdoc1/USANews_', i, '_0.html', sep='') html <- content(GET("http://www.mitbbs.com/", path = url),as = 'parsed') url.list <

ggplot add Normal Distribution while using `facet_wrap` [duplicate]

☆樱花仙子☆ 提交于 2021-02-19 07:53:06
问题 This question already has answers here : using stat_function and facet_wrap together in ggplot2 in R (6 answers) Closed 21 days ago . I'm looking to plot the following histograms: library(palmerpenguins) library(tidyverse) penguins %>% ggplot(aes(x=bill_length_mm, fill = species)) + geom_histogram() + facet_wrap(~species) For each histogram, I would like to add a Normal Distribution to each histogram with each species mean and standard deviation. Of course I'm aware that I could compute the

ggplot add Normal Distribution while using `facet_wrap` [duplicate]

谁说胖子不能爱 提交于 2021-02-19 07:52:51
问题 This question already has answers here : using stat_function and facet_wrap together in ggplot2 in R (6 answers) Closed 21 days ago . I'm looking to plot the following histograms: library(palmerpenguins) library(tidyverse) penguins %>% ggplot(aes(x=bill_length_mm, fill = species)) + geom_histogram() + facet_wrap(~species) For each histogram, I would like to add a Normal Distribution to each histogram with each species mean and standard deviation. Of course I'm aware that I could compute the

Looping through R Plotly with subplot and hiding all legend except one

和自甴很熟 提交于 2021-02-19 07:48:05
问题 I need to loop through i iteration of factors, and each factor needs to be plotted as one plot in a subplot. What I would like to do is hiding the legend for every iteration bar the first one, and use legendgroup to tie all the legends together. This is what I have done so far: library(plotly) library(dplyr) mtcars %>% mutate(vs = as.factor(vs)) %>% group_split(cyl) %>% lapply(function(i) { #show.legend <- ifelse(i == 1, TRUE, FALSE) show.legend <- if(i == 1) {TRUE} else {FALSE} plot_ly( data

plotting multiple geom-vline in a graph

怎甘沉沦 提交于 2021-02-19 07:46:06
问题 I am trying to plot two ´geom_vline()´ in a graph. The code below works fine for one vertical line: x=1:7 y=1:7 df1 = data.frame(x=x,y=y) vertical.lines <- c(2.5) ggplot(df1,aes(x=x, y=y)) + geom_line()+ geom_vline(aes(xintercept = vertical.lines)) However, when I add the second desired vertical line by changing vertical.lines <- c(2.5,4) , I get the error: ´Error: Aesthetics must be either length 1 or the same as the data (7): xintercept´ How do I fix that? 回答1: Just remove aes() when you

Differentiate lines in geom_dumbbel by colour using levels of a variable

天大地大妈咪最大 提交于 2021-02-19 07:44:12
问题 I am trying to differentiate the lines by a variable "Trial_type", which has two levels. One of the levels is retention and I want that line to be blue, and the other level, transfer I want it to be red. I hope this produces a legend to make the plot more understandable. I have the plot made just missing those key ingredients. library(ggplot2) library(ggalt) library(tidyverse) library(dplyr) data10 <- structure(list(GROUP = c("RLR", "LRL", "RLR", "LRL", "RLR", "LRL", "RRR", "LLL", "RRR", "LLL

Find all local maxima of a geom_smooth curve in R ggplot?

回眸只為那壹抹淺笑 提交于 2021-02-19 07:40:52
问题 I need to find all local maxima of a geom_smooth() curve in R. This has been asked in Stack Overflow before: How can I get the peak and valleys of a geom_smooth line in ggplot2? But the answer related to finding a single maximum. What if there are multiple local maxima we want to find? Here's some sample data: library(tidyverse) set.seed(404) df <- data.frame(x = seq(0,4*pi,length.out=1000), y = sin(seq(0,4*pi,length.out=1000))+rnorm(100,0,1)) df %>% ggplot(aes(x=x,y=y)) + geom_point() + geom

Find all local maxima of a geom_smooth curve in R ggplot?

徘徊边缘 提交于 2021-02-19 07:39:49
问题 I need to find all local maxima of a geom_smooth() curve in R. This has been asked in Stack Overflow before: How can I get the peak and valleys of a geom_smooth line in ggplot2? But the answer related to finding a single maximum. What if there are multiple local maxima we want to find? Here's some sample data: library(tidyverse) set.seed(404) df <- data.frame(x = seq(0,4*pi,length.out=1000), y = sin(seq(0,4*pi,length.out=1000))+rnorm(100,0,1)) df %>% ggplot(aes(x=x,y=y)) + geom_point() + geom

Convert YYYY-MM-DD to YYYY-YY Qx in R

て烟熏妆下的殇ゞ 提交于 2021-02-19 07:39:20
问题 I'm trying to plot data by quarter then display in ggplot. Dates in dataset are of the format YYYY-MM-DD, and I want the ggplot x-axis to display the financial year like YYYY-YY Qx. The financial year starts July 1. Data is in long format. This is where I've got to: Data set named: TOX TREE_ID PM_Date variable value 1: 2013000584 2013-04-02 elm 0 2: 2013000498 2013-06-11 elm 1 3: 2013000123 2013-09-03 maple 0 4: 2013000642 2014-02-15 maple 0 5: 2013000778 2016-07-08 maple 1 PM_Dateq <- as

R Shiny how to display a pdf file generated in “downloadHandler”

梦想的初衷 提交于 2021-02-19 07:37:59
问题 I am new to shiny and was wondering if there is a way to display a pdf file generated in "downloadHandler"? I am using a package to do some biological analysis, and I can make it create a pdf file in downloadHandler. However, I am still struggling if I can view this pdf instead of downloading it. This question is related to Shiny to output a function that generates a pdf file itself. Please see the below for the code that works for downloading the pdf output. Thanks so much! library(shiny)