-
[R] Grouped Bar Chart by plotlyPrograming/Data Science 2021. 3. 8. 15:47
이번에는 Plotly 를 이용해 그룹 바 그래프를 그리는 코드입니다.
library(plotly) groups <- c("Group A", "Group B", "Group C") group_value1 <- c(0.1234, 0.2345, 0.4567) group_value2 <- c(0.2342, 0.3564, 0.7684) data <- data.frame(groups, group_value1, group_value2) # rgba: red, green, blue and alpha color1 <- "rgba(105, 105, 105, 0.6)" color2 <- "rgba(255, 0, 0, 0.6)" # texttemplate: to define the format of annotated text fig <- plot_ly(data, x = ~groups, y = ~group_value1, text = ~group_value1, texttemplate="%{y:.4f}", textposition = 'outside', textfont = list(color=color1), type = 'bar', marker=list(color = color1), name = 'Case 1') fig <- fig %>% add_trace(y = ~group_value2, text = ~group_value2, textfont=list(color=color2), marker=list(color = color2), name = 'Case 2') # title="" : to remove title of xaxis, tickformat: to set the format of ticks in axis fig <- fig %>% layout(legend=list(x = 0.5, y= 0.9), yaxis = list(tickformat=".1f", title = 'Y axis title', titlefont=list(size=18), range = c(0, 1.0)), barmode = 'group', xaxis = list(categoryorder = "array", categoryarray = ~groups, title="", titlefont=list(size=10))) fig
'Programing > Data Science' 카테고리의 다른 글
[엑셀] CSV 파일 저장시 구분자 변경 (0) 2022.02.11 [Plotly][ValueError] executable=" ".join(executable_list), help_result=help_result (0) 2020.04.03 [Python] subplot 에 shape 추가하기 (0) 2020.04.03 [R] color names (0) 2020.03.26 [R] Plotly 에서 marker 사용하기 (0) 2020.02.24