Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    emilyluckey
    @emilyluckey
    df_taoyuanMarriage %>%
      gather(
        grep("月$",colnames(.)),
        key = "年份", value = "對數"
      )
    tim8537099
    @tim8537099
    library(readr)
    X27b5594a385573df182ebb70880cdcbe <- read_csv("http://opendataap2.hl.gov.tw/./resource/files/2019-03-15/27b5594a385573df182ebb70880cdcbe.csv")
    View(X27b5594a385573df182ebb70880cdcbe)
    funkjerry
    @funkjerry
    library(readr)
    DownloadFile <- read_csv("http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx?DATA=9796A044-5B71-4194-978C-5148AD7D8DB9",
    locale = locale(encoding = "BIG5"))
    View(DownloadFile)
    Jimmyflash229
    @Jimmyflash229
      library(readr)
    X69786f76_5d6b_4c19_8614_95c3e18ea873 <- read_csv("http://datacenter.taichung.gov.tw/swagger/OpenData/69786f76-5d6b-4c19-8614-95c3e18ea873")
    View(X69786f76_5d6b_4c19_8614_95c3e18ea873)
    emilyluckey
    @emilyluckey
    download_id_64a896aa_a6aa_4362_90fb_4270d90ff625_rid_85e11adb_c228_4b57_a7fd_1d99fb31129c <- read_csv("https://data.tycg.gov.tw/opendata/datalist/datasetMeta/download?id=64a896aa-a6aa-4362-90fb-4270d90ff625&rid=85e11adb-c228-4b57-a7fd-1d99fb31129c")
    KaEDe1106
    @KaEDe1106
    TrainDeathNumber2018 <- read_csv("http://ods.railway.gov.tw/tra-ods-web/ods/download/dataResource/8ae4cabe6c8578b2016c8a2a14043137", 
        locale = locale())
    TrainDeathNumber2018
    emilyluckey
    @emilyluckey
    subsetDataTWbank %>%
      gather(
        `定存利率-一個月-固定`,`定存利率-二年期-固定`,`定存利率-三年期-固定`,
        key = "期數", value = "利率"
      ) %>%
      ggplot() +
      geom_point(
        aes(x=期數,y=利率,color=西元年月)
      )
    godgodgod11101
    @godgodgod11101
    
    data.frame(
      x1 = factor(sample(c(1L,2L,3L),100,replace=T)),
      x2 = runif(100),
      y = runif(100),
      z1 = rnorm(100),
      z2 = factor(sample(letters[1:4],100,replace=T))
    ) -> df_example
    
    df_example %>%
      ggplot()+
      geom_boxplot(
        aes(x=x1,y=y,fill=z2)
      ) -> basicBoxplot
    basicBoxplot
    
    colorspace::qualitative_hcl(n = 7, h = c(0, 360), c = 35, l = 85, register = "Custom-Palette")
    
    basicBoxplot +
      scale_fill_discrete_qualitative(palette="Custom-Palette",nmax=5)
    emilyluckey
    @emilyluckey
    library(readr)
    disposableIncome <- read_csv("https://www.dropbox.com/s/z80sbjw94cjex8x/disposableIncome.csv?dl=1",
    locale = locale(encoding = "BIG5"), skip = 4)
    library(dplyr)
    library(tidyr)
    colnames(disposableIncome)[[1]] <- "年份"
    
    disposableIncome %>%
      .[-c(44:49),] -> disposableIncome
    
    as.numeric(disposableIncome$年份) -> 
      disposableIncome$年份
    
    disposableIncome %>%
      filter(年份 >= 2003) %>%
      gather(
        -1,
        key = "組別", value = "元"
      ) %>%
      ggplot() +
      geom_line(
        aes(x=年份, y=元, color = 組別)
      )
    Martin老師
    @tpemartin
    c('X1','平均每戶可支配所得','可支配所得按戶數五等分位組-最低所得組','可支配所得按戶數五等分位組-次低所得組','可支配所得按戶數五等分位組-中間所得組','可支配所得按戶數五等分位組-次高所得組','可支配所得按戶數五等分位組-最高所得組') -> names(disposableIncome)
    emilyluckey
    @emilyluckey
    Encoding<-(disposableIncome$X1,"utf-8") -> disposableIncome$X1
    `Encoding<-`(disposableIncome$X1,"utf-8") -> disposableIncome$X1
    Martin老師
    @tpemartin
    c('年分','地區','來台旅遊人數(萬)') -> names(graphData$travelerFromAsia)
    asus50901
    @asus50901
    load(url("https://github.com/tpemartin/course-108-1-inclass-datavisualization/blob/master/%E4%BD%9C%E5%93%81%E5%B1%95%E7%A4%BA/graphData_homework2019-10-08_014.Rda?raw=true"))
    
    # rename the column names cause its messy and just wrong
    colnames(graphData$travelerFromAsia) <- c("年分", "地區", "來台旅遊人數(萬)")
    
    graphData$travelerFromAsia$年分 <- as.numeric(graphData$travelerFromAsia$年分)
    
    graphData$travelerFromAsia %>%
      ggplot(aes(x=`年分`,y=`來台旅遊人數(萬)`,color = 地區, linetype = 地區)) +
      geom_line()
    Martin老師
    @tpemartin
    Martin老師
    @tpemartin
    names(graphData$data) <- c("年份", "國民所得儲蓄投資毛額", "毛額")
    Martin老師
    @tpemartin
    Martin老師
    @tpemartin
    data.frame(
      x=x,
      xinterval=x_interval
    ) -> df_x
    df_x %>% View
    Hsinyung
    @Hsinyung
    老師,我想請問一下,圖例的標題要怎麼改呢?
    我上網查了很多種打法都沒用
    graphData$traffic %>%
      melt(id.vars="年別") %>%
        ggplot(aes(x=年別,
                   y=value)) + 
        geom_line(aes(color=variable),size=1.2
                ) +
      geom_vline(aes(xintercept=2015),size = 0.005)+
      geom_hline(aes(yintercept=0),linetype="twodash",size = 0.05,color="red") +
      scale_color_discrete_sequential(palette="Custom-Palette")+
      labs(title = "2012-2017大眾運輸工具載客變化",
           subtitle="(以2012為基期)",
           x = "年份",y = "載客量",legend.title = element_text("運輸工具"))
    這是我目前的打法
    Hsinyung
    @Hsinyung
    graphData$traffic %>%
      melt(id.vars="年別") %>%
        ggplot(aes(x=年別,
                   y=value)) + 
        geom_line(aes(color=variable),size=1.2
                ) +
      geom_vline(aes(xintercept=2015),size = 0.005)+
      geom_hline(aes(yintercept=0),linetype="twodash",size = 0.05,color="red") +
      scale_color_discrete_sequential(palette="Custom-Palette")+
      labs(title = "2012-2017大眾運輸工具載客變化",
           subtitle="(以2012為基期)",
           x = "年份",y = "載客量")+
      scale_fill_discrete(name = "運輸工具")
    我看講義的scale_fill這串也不行
    Martin老師
    @tpemartin
    只有aes(...)的才會有圖例,所以你只能針對x, y, color去產生圖例
    asus50901
    @asus50901
    Legend.title 是放在theme()裡面的
    Labs只能放 title subtitle caption x y
    asus50901
    @asus50901
    你的ggplot(aes())裡面沒有寫fill 所以scale_fill_discrete 會抓不到fill啥
    問題應該出在這 不過最好要看error 回傳什麼
    Hsinyung
    @Hsinyung
    好的,謝謝
    Martin老師
    @tpemartin
    lengend會對應某個aes mapping variable, 要改它要從此aes的scale_函數下手。假設是aes mapping variable是這裡的color,因此要去scale_color改; 你用的是scale_color_discrete_sequential(), 所以在那設定。在每個scale_...()下有一個設定為guide,你要給它一個list of guide setting ,一般透過guide_lengend(), 所以這裡你要用:
    scale_color_discrete_sequential(...., guide=guide_legend(***))
    *的設定可以看https://ggplot2.tidyverse.org/reference/guide_legend.html
    asus50901
    @asus50901
    # Run one codeline at a time
    
    if(!require(installr)) {
      install.packages("installr");
      require(installr)
    }
    
    updateR()
    
    update.packages(ask = FALSE, checkBuilt =  TRUE)
    `
    asus50901
    @asus50901
    options(scipen = 99) # 去除科學記號
    asus50901
    @asus50901
    library(readr)
    df_geo_northTW <- read_csv("https://www.dropbox.com/s/6uljw24zkyj7avs/df_geo_northTW.csv?dl=1")
    
    north <- df_geo_northTW %>% filter(COUNTYNAME == "新北市")
    
    northTW <-ggplot() +
      geom_polygon(
        data=north,
        aes(x=x,y=y)
      )
    
    northTW
    shuyulin97
    @shuyulin97
    df_geo_northTW %>%
      filter(COUNTYNAME == "新北市") %>%
      ggplot(aes(x = x, y = y))+geom_polygon()
    asus50901
    @asus50901
    ggthemes:::theme_economist
    getAnywhere(theme_economist)
    View(ggtheme::theme_economist)
    asus50901
    @asus50901
    三個都可以看function 的原始碼
    Martin老師
    @tpemartin
    outer <-     
      rbind( # 外圍
        c(1,5),
        c(2,1),
        c(5,1),
        c(5,5),
        c(1,5)) # 必需自行輸入起點close it
    
    hole <-
      rbind( # 洞
        c(2,4),
        c(3,2),
        c(4,3),
        c(2,4))  # 必需自行輸入起點close it
    
    outer2 <- outer + 12
    hole2 <- hole + 12
    emilyluckey
    @emilyluckey
    finalplot.png
    Martin老師
    @tpemartin
    download.file("http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx?DATA=72874C55-884D-4CEA-B7D6-F60B0BE85AB0",
                  destfile="tw.zip")
    unzip("tw.zip",exdir="taiwan")
    read_sf("taiwan/COUNTY_MOI_1080726.shp")-> sf_taiwan
    Martin老師
    @tpemartin
    load(url("https://www.dropbox.com/s/uvco1te2kbs6o01/MRT_Taipei.Rda?dl=1"))
    取得BL
    sf_mrtStops_tpe %>%
      filter(
        str_detect(經過路線,"BL")
      ) -> sf_mrtStops_tpe_BL
    
    sf_mrtStops_BL %>% View
    取得站號
    sf_mrtStops_BL %>%
      mutate(
          站號=str_extract(經過路線,"(?<=(BL))[:digit:]+")
                ) %>%
      arrange(站號) -> sf_mrtStops_BL
    
    sf_mrtStops_BL %>% View
    Martin老師
    @tpemartin
    畫圖
    sf_northTaiwan %>%
      ggplot()+geom_sf()+
      geom_sf(
        data=sf_mrtStops_BL
      )+
      coord_sf(
        xlim=c(121.4,121.7),
        ylim=c(24.9,25.1)
      ) -> gg_tpe_mrt
    gg_tpe_mrt