by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    emilyluckey
    @emilyluckey
    `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
    asus50901
    @asus50901
    JPisland.jpeg
    Chen-Ying-Chen
    @Chen-Ying-Chen
    永和四號公園.png
    shuyulin97
    @shuyulin97
    Imgur
    Hsinyung
    @Hsinyung
    00001d.png
    godgodgod11101
    @godgodgod11101
    mapSSairport.png
    shihhanChiu
    @shihhanChiu
    000037.png
    sunnyzeng
    @sunnzeng
    dzsh.png
    Ching-Hsuan
    @Ching-Hsuan
    plot_zoom_png (1)
    KaEDe1106
    @KaEDe1106
    image.png
    emilyluckey
    @emilyluckey
    捲尾家.png
    LINYICHI017
    @LINYICHI017