by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    asus50901
    @asus50901
    collegeData <- read_csv("https://raw.githubusercontent.com/tpemartin/github-data/master/103_student.csv")
    
    str(collegeData)
    
    dplyr::slice(collegeData, 1:4)
    dplyr::slice(collegeData, (n()-2):n())
    dplyr::slice(collegeData, 101:110)
    Martin老師
    @tpemartin
    str(collegeData)
    slice(collegeData,c(1:4))
    slice(collegeData,(n()-2):n())
    slice(collegeData,101:110)
    LINYICHI017
    @LINYICHI017
    slice(collegeData , 1:4) %>% View
    slice(collegeData, c((n()-2),(n()-1),n())) %>% View
    funkjerry
    @funkjerry
    mutate(collegeData,
           男生=一年級男生+二年級男生+三年級男生+四年級男生)-> collegeData
    
    collegeData$女生 <-
      collegeData$一年級女生+collegeData$二年級女生+collegeData$三年級女生+collegeData$四年級女生
    
    collegeData$男女生比<-collegeData$男生/collegeData$女
    shuyulin97
    @shuyulin97
    #在collegeData:
    ##新增變數男生及女生,其值為「一到四年級」所有男生及女生的加總。(男生使用dplyr, 女生不使用dplyr)
    
    #男生
    collegeData <- mutate(collegeData, 男生 = collegeData[[5]]+collegeData[[7]]+collegeData[[9]]+collegeData[[11]])
    
    #女生
    collegeData$女生 <- collegeData[[6]]+collegeData[[8]]+collegeData[[10]]+collegeData[[12]]
    
    #新增變數男女生比,其值為前述男生/女生。
    collegeData$男女生比 <- collegeData$男生/collegeData$女生
    KaEDe1106
    @KaEDe1106
    collegeData <- mutate(collegeData,男生=一年級男生+二年級男生+三年級男生+四年級男生)
    
    collegeData$女生<-collegeData$一年級女生+collegeData$二年級女生+collegeData$三年級女生+collegeData$四年級女生
    
    collegeData$男女生比 <- collegeData$男生/collegeData$女生
    
    collegeData
    ningtraveo75
    @ningtraveo75
    mutate(collegeData,
           男生=一年級男生+二年級男生+三年級男生+四年級男生) -> collegeData
    collegeData$女生 <- collegeData$一年級女生+collegeData$二年級女生+collegeData$三年級女生+collegeData$四年級女生
    
    mutate(collegeData,男女生比=男生/女生) -> collegeData
    hhhhhsin
    @hhhhhsin
    collegeData
    mutate(collegeData,
           男生=一年級男生+二年級男生+三年級男生+四年級男生)->collegeData
    
    collegeData$女生 <-
      collegeData$一年級女生+collegeData$二年級女生+collegeData$三年級女生+collegeData$四年級女生
    
    collegeData$男女生比<-collegeData$男生/collegeData$女
    Chen-Ying-Chen
    @Chen-Ying-Chen
    collegeData
    ##新增男生變數
    mutate(collegeData,
           男生=一年級男生+二年級男生+三年級男生+四年級男生) -> collegeData 
    ##新增女生變數
    collegeData$女生 <-
    collegeData$一年級女生+collegeData$二年級女生+collegeData$三年級女生+collegeData$四年級女生 
    ##新增男女生比
    mutate(collegeData,
           男女生比=男生/女生) -> collegeData
    hhhhhsin
    @hhhhhsin
    mutate(StuDF,
            調分成績=(成績+(max(成績)-min(成績))/5))
    Martin老師
    @tpemartin
    mutate(StuDF,
            平均成績=mean(成績),
            最高分=max(成績),
            最低分=min(成績),
            調整後成績=成績+(最高分-最低分)/5)
    emilyluckey
    @emilyluckey
    StuDF %>%
      filter(
        性別 == "女"
      ) %>%
      summarise(
        平均成績 = mean(成績),
        最高分 = max(成績),
        最低分 = min(成績)
      )
    hhhhhsin
    @hhhhhsin
    #1
    collegeData
    filter(collegeData,
           縣市名稱=="30 臺北市")
    #2
    filter(collegeData,
           縣市名稱=="30 臺北市" | 縣市名稱=="01 新北市")
    ningtraveo75
    @ningtraveo75
    # 縣市名稱為“30 臺北市”
    filter(collegeData,
           縣市名稱=="30 臺北市")
    # 縣市名稱為“30 臺北市”或“01 新北市”
    filter(collegeData,
           縣市名稱=="30 臺北市" | 縣市名稱=="01 新北市")
    emilyluckey
    @emilyluckey
    #1
    str_detect(
      collegeData$縣市名稱,
      "30"
    ) %>%
      collegeData[.,]
    KaEDe1106
    @KaEDe1106
    collegeData[collegeData$縣市名稱=="30 臺北市",]
    
    filter(collegeData,
           縣市名稱=="30 臺北市"|
           縣市名稱=="01 新北市")
    emilyluckey
    @emilyluckey
    collegeData %>%
      group_by(縣市名稱,體系別) %>%
      summarise(
        一年級男生人數 = sum(一年級男生),
        一年級女生人數 = sum(一年級女生),
        學校數目 = n()
      )
    godgodgod11101
    @godgodgod11101
    
    group_by(collegeData,
             縣市名稱, 體系別, 
             ) -> collegeData_by縣市and體系
    
    summarise(collegeData_by縣市and體系, 
              一年級男生總數 = sum(一年級男生), 
              一年級女生總數 = sum(一年級女生), 
              學校數目 = n()
              )
    shuyulin97
    @shuyulin97
    ##計算collegeData中不同縣市名稱及體系別的一年級男生及一年級女生總數(使用sum)和學校數目。
    #分群不同縣市名稱及體系別
    collegeData_group <- group_by(collegeData,
                                  縣市名稱,
                                  體系別)
    
    #計算
    summarise(collegeData_group,
              一年級男生總數 = sum(一年級男生),
              一年級女生總數 = sum(一年級女生),
              學校數目 = n())
    ningtraveo75
    @ningtraveo75
    group_by(collegeData,縣市名稱,體系別) -> collegeData_by
    summarise(collegeData_by,
              一年級男生總數=sum(一年級男生),
              一年級女生總數=sum(一年級女生),
              學校數目=n())
    Martin老師
    @tpemartin
    計算每位學生每學年每學期的平均成績。
    transcriptDataFinal %>%
      group_by(學號,學年,學期) %>%
      summarise(
        平均成績=sum(學期成績*學分數)/sum(學分數)
      )
    KaEDe1106
    @KaEDe1106
    gather(df_taoyuanMarriage,
           -月份區域別,
           key="月份",value="")
    Chen-Ying-Chen
    @Chen-Ying-Chen
    gather(df_taoyuanMarriage,
           ends_with("月"),
           key="月份",value="對數"
          )
    shihhanChiu
    @shihhanChiu
    df_taoyuanMarriage%>%
      gather(
        ends_with("月"),
        key = "月份",value = "對數"
      )
    st85611
    @st85611
    df_taoyuanMarriage
    gather(df_taoyuanMarriage,
          -月份區域別,
           key="月份",value="人數")
    asus50901
    @asus50901
    df_taoyuanMarriage %>%
    gather(ends_with("月"), key = "月數", value = "對數") %>%
    group_by(月數) %>%
    dplyr::summarise(總結婚對數 = sum(對數))
    KaEDe1106
    @KaEDe1106
    df_taoyuanMarriage %>%
      gather(-月份區域別,
              key="月份",value="對數") %>%
                group_by(月份) %>%
                  summarise(總結婚對數=sum(對數))
    asus50901
    @asus50901
    df_taoyuanMarriage %>%
      gather(ends_with("月"), key = "月數", value = "對數") %>%
      group_by(月份區域別) %>%
      dplyr::summarise(最高峰月份 = which.max(`對數`))
    Chen-Ying-Chen
    @Chen-Ying-Chen
    df_taoyuanMarriage%>%
    gather(
           ends_with("月"),
           key="月份",value="對數"
          )%>%group_by(月份區域別)%>%summarise(結婚最高峰月份=which.max(對數))
    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("運輸工具"))