Last active
August 22, 2019 12:10
-
-
Save axjack/189cbdc8f5e495e8aae281f7fef9ed89 to your computer and use it in GitHub Desktop.
増減分析
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load library #### | |
library(dplyr) | |
library(tidyr) | |
library(maptools) | |
# make data #### | |
dd <- data.frame( | |
dept=rep(c('d1','d2','d3','d4','d5'),each=10) | |
,ym=rep(seq(201808,201812,1),10) | |
,cat=rep(rep(c('c1','c2'),each=5),5) | |
,mp=sample(x=10:40,size = 50,replace = T) | |
) | |
# maipulate #### | |
dd %>% arrange(dept,cat,ym) %>% | |
group_by(dept,cat) %>% | |
mutate(mp1=lead(mp)) %>% | |
mutate(mp_diff = mp1 - mp) %>% | |
mutate(sign_plus = ifelse(mp_diff > 0 , 1, 0 )) %>% | |
summarise( mysum = sum(sign_plus, na.rm = TRUE)) %>% | |
spread(key = cat, value = mysum) -> dd.modified | |
# graph #### | |
plot(c2~c1, data=dd.modified) | |
abline(h = median(dd.modified$c2), lty=3) | |
abline(v = median(dd.modified$c1), lty=3) | |
pointLabel(dd.modified$c1, dd.modified$c2, labels = dd.modified$dept) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment