r

ggplot2 mapping county boundries in one color and state boundries in another on the same map

喜夏-厌秋 提交于 2021-02-17 16:42:35
问题 I am creating a choropleth county map with grey borders, and I also want to include the state boundries in black. Does anyone know how I go about adding a second layer of state mapping to an existing county map? Here's the data set and code I ended up using: #load libraries library(ggplot2) library(ggmap) library(maps) library(plyr) #get wif file wip <- read.csv("wip.csv") #get map data for US counties and states county_map <- map_data("county") state_map <- map_data("state") #merge wip and

ggplot2 mapping county boundries in one color and state boundries in another on the same map

淺唱寂寞╮ 提交于 2021-02-17 16:39:36
问题 I am creating a choropleth county map with grey borders, and I also want to include the state boundries in black. Does anyone know how I go about adding a second layer of state mapping to an existing county map? Here's the data set and code I ended up using: #load libraries library(ggplot2) library(ggmap) library(maps) library(plyr) #get wif file wip <- read.csv("wip.csv") #get map data for US counties and states county_map <- map_data("county") state_map <- map_data("state") #merge wip and

How to generate multiple files from r script function with knitr

拜拜、爱过 提交于 2021-02-17 15:00:26
问题 I would like to generate a number of reports from an r script. I would like to avoid the duplication needed when compiling from rmd files and I'd like to generate the reports from the r script itself if possible. The script has a function which should generate each report from a list of dataframes where each report represents the processing of one dataframe. I just can't understand how to generate each report separately. At the moment the report shows all of the dataframes in one file The

R programming: How do I get Euler's number?

早过忘川 提交于 2021-02-17 14:29:37
问题 For example, how would I go about entering the value e^2 in R? 回答1: The R expression exp(1) represents e, and exp(2) represents e^2. This works because exp is the exponentiation function with base e. 回答2: -digamma(1) is the Euler's Constant in R. e , ( exp(1) in R), which is the natural base of the natural logarithm Euler's Constant. Euler's Number 回答3: if you want to have a little number e to play with, you can also make one yourself: emake <- function(){ options("warn"=-1) e <- 0 for (n in

缺失值及处理

我怕爱的太早我们不能终老 提交于 2021-02-17 13:10:31
is.na() 检测缺失值是否存在 > y <- c(1,2,NA,3) > is.na(y) [1] FALSE FALSE TRUE FALSE #注意 is.na()函数是如何作用于一个对象上的,它将返回一个相同大小的对象 #某个元素是 NA ,则返回TRUE ,否则返回 FALSE 注意 a、在R中,缺失值被认为是不可比较的,即便是缺失值自身的比较,这意味着无法使用比较运算符来检测是否存在,例如,逻辑测试myvar == NA 的结果永远不会为TRUE b、R并不能把无限的或不可能出现的数值标记成缺失值 正无穷:Inf 负无穷:-Inf 5/0返回:Inf 不可能的值,比如说 sin(Inf)用NaN符号来标记(not a number),如要识别这些数值,则用到is.infinite()或is.nan() c、含有缺失值的算术表达式和函数的计算结果也是缺失值 na.rm选项、na.omit() na.rm = TRUE na.omit() 移除所有含有缺失值的观测,即删除整行 y <- c(1,2,NA,3) x <- sum(y,na.rm=T) # na.rm =T 移除NA值 z <- na.omit(leadership) #删除含有NA的观测 注: NA(缺失值) 与 NULL 是不同的 来源: oschina 链接: https://my.oschina

Insert a logo in upper right corner of R markdown html document

∥☆過路亽.° 提交于 2021-02-17 08:31:15
问题 I'm trying to put my company logo on the right corner of my html document Here my code: <script> $(document).ready(function() { $head = $('#header'); $head.prepend('<div class="knitr source"><img src="logo.png" width="220px" align="right" ></div>') }); </script> --- title: "Title" author: "Author" date: "Date" theme: bootstrap output: html_document keep_md: true --- ```{r echo=FALSE, include=FALSE} knitr::include_graphics('./logo.png') ``` <br> ## 1) Header <br> Lorem ipsum dolor sit amet,

Removing one level/group from Facet_wrap ggplot2 in R

你说的曾经没有我的故事 提交于 2021-02-17 07:15:06
问题 My tbl_df: > str(p2p_dt_SKILL_A) Classes ‘tbl_dt’, ‘tbl’, ‘data.table’ and 'data.frame': 693 obs. of 35 variables: $ Patch : Factor w/ 7 levels "BVG1","BVG11",..: 1 2 3 4 5 6 7 1 2 3 ... $ Skill : Factor w/ 15 levels "A","BROADBAND",..: 1 1 1 1 1 1 1 1 1 1 ... $ Date : Date, format: "2015-12-04" "2015-12-04" "2015-12-04" "2015-12-04" ... $ SOD_FWIH_A : num 1.09 1.14 1.09 1.1 1.09 1.07 1.09 1.07 1.12 1.07 ... $ Prod_MWF : num 5.06 5.06 5.44 5.34 4.22 4.72 4.89 4.68 4.68 5.22 ... $ Prod_MA :

How to order multiple dataframes in Global Environment R

删除回忆录丶 提交于 2021-02-17 07:13:45
问题 I'm trying to Run a simulation but I'm having trouble storing multiple dataframes called "data_i" in a list ordering by i. I start with a df called "data_", which has data from 1901 to 2032 (132 rows). I apply a loop to create one dataframe per row called data_1, data_2,data_3,...,data_132 (row of 2032 is stored in data_132). Finally, I store all this dataframes in a list and use lapply to create a column in each dataframe. Here is a reproducible example: #Main dataframe time <- 1901:2032 b <

R How to group_by, split or subset by row values

拜拜、爱过 提交于 2021-02-17 07:08:07
问题 This is continued from last question R, how to group by row value? Split? The change in input Dataframe is id = str_c("x",1:22) val = c(rep("NO1", 2), "START", rep("yes1", 2), "STOP", "NO", "START","NO1", "START", rep("yes2", 3), "STOP", "NO1", "START", rep("NO3",3), "STOP", "NO1", "STOP") data = data.frame(id,val) Expected output is dataframe with val column as follows- val = c("START", rep("yes1", 2), "STOP", "START","NO1", "START", rep("yes2", 3), "STOP", "START", rep("NO3",3), "STOP",

how to generate random numbers from a shifted to the left chi square distribution in R?

谁说我不能喝 提交于 2021-02-17 07:07:15
问题 I want to generate random numbers from chi-square distribution with 3 degrees of freedom but shifted to the left . I mean the shifted distribution function f(x-a) a is the amount of shifting. in r it is said the non centrality parameter must be non negative. 回答1: Let's look at the Chi-square distribution with 3 degrees of freedom: x_vals <- seq(0, 10, 0.1) plot(x_vals, dchisq(x_vals, 3), type = "l", main = "Chi Squared distribution of x with 3 DOF") Now let's shift it to the left by a