Commit 9d1f5677 authored by dmattek's avatar dmattek
Browse files

added: rotated x-axis labels

parent 554bb9a8
...@@ -40,15 +40,19 @@ install.packages(c("shiny", "shinyjs", ...@@ -40,15 +40,19 @@ install.packages(c("shiny", "shinyjs",
``` ```
**Note** **Note**
As of July 2018, *sparcl* has been removed from CRAN. If you don't need sparse hierarchical clustering, you can simply comment the line `library(sparcl)` in `server.R` file or install it from the [archive](https://cran.r-project.org/web/packages/sparcl/index.html). As of July 2018, *sparcl* has been removed from CRAN. If you don't need sparse hierarchical clustering, you can simply comment the line `library(sparcl)` in `server.R` file or install it from the [archive](https://cran.r-project.org/web/packages/sparcl/index.html):
**Additionally**, a time series analysis package need to be installed from [GitHub](https://github.com/dmattek/tca-package): ```
install_url('https://cran.r-project.org/src/contrib/Archive/sparcl/sparcl_1.0.3.tar.gz')
```
**Additionally**, a time series analysis package needs to be installed from [GitHub](https://github.com/dmattek/tca-package):
``` ```
install_github("dmattek/tca-package") install_github("dmattek/tca-package")
``` ```
The `install_github` function is available in *devtools* package: The `install_url` and `install_github` functions are available in *devtools* package:
``` ```
install.packages("devtools") install.packages("devtools")
......
...@@ -170,6 +170,22 @@ getClCol <- function(in.dend, in.k) { ...@@ -170,6 +170,22 @@ getClCol <- function(in.dend, in.k) {
##### #####
## Common plotting functions ## Common plotting functions
# Build Function to Return Element Text Object
# From: https://stackoverflow.com/a/36979201/1898713
rotatedAxisElementText = function(angle, position='x', size = 12){
angle = angle[1];
position = position[1]
positions = list(x=0, y=90, top=180, right=270)
if(!position %in% names(positions))
stop(sprintf("'position' must be one of [%s]",paste(names(positions),collapse=", ")), call.=FALSE)
if(!is.numeric(angle))
stop("'angle' must be numeric",call.=FALSE)
rads = (-angle - positions[[ position ]])*pi/180
hjust = round((1 - sin(rads)))/2
vjust = round((1 + cos(rads)))/2
element_text(size = 12, angle = angle, vjust = vjust, hjust = hjust)
}
myGgplotTheme = myGgplotTheme =
theme_bw(base_size = 8, base_family = "Helvetica") + theme_bw(base_size = 8, base_family = "Helvetica") +
theme( theme(
......
...@@ -31,7 +31,6 @@ modBoxPlotUI = function(id, label = "Plot Box-plots") { ...@@ -31,7 +31,6 @@ modBoxPlotUI = function(id, label = "Plot Box-plots") {
), ),
selected = 'top' selected = 'top'
), ),
checkboxInput(ns('chBxAxisLabelsRotate'), 'Rotate x-axis labels?'),
uiOutput(ns('uiPlotBoxNotches')), uiOutput(ns('uiPlotBoxNotches')),
uiOutput(ns('uiPlotBoxOutliers')), uiOutput(ns('uiPlotBoxOutliers')),
uiOutput(ns('uiPlotBoxDodge')), uiOutput(ns('uiPlotBoxDodge')),
...@@ -56,7 +55,11 @@ modBoxPlotUI = function(id, label = "Plot Box-plots") { ...@@ -56,7 +55,11 @@ modBoxPlotUI = function(id, label = "Plot Box-plots") {
min = 100, min = 100,
width = '100px', width = '100px',
step = 50 step = 50
) ),
radioButtons(ns("rBAxisLabelsRotate"), "X-axis labels:",
c("horizontal" = 0,
"45deg" = 45,
"90 deg" = 90))
) )
), ),
...@@ -238,15 +241,9 @@ modBoxPlot = function(input, output, session, ...@@ -238,15 +241,9 @@ modBoxPlot = function(input, output, session,
ylab('') + ylab('') +
ggplotTheme() + ggplotTheme() +
#myGgplotTheme + #myGgplotTheme +
theme(legend.position = input$selPlotBoxLegendPos) theme(legend.position = input$selPlotBoxLegendPos,
axis.text.x = element_text(size = 12, angle = as.numeric(input$rBAxisLabelsRotate), hjust = ifelse(input$rBAxisLabelsRotate == 0, 0, 1)))
if (input$chBxAxisLabelsRotate)
p.out = p.out +
theme(axis.text.x = element_text(size = 12, angle = 45, hjust = 1))
else
p.out = p.out +
theme(axis.text.x = element_text(size = 12))
return(p.out) return(p.out)
} }
......
...@@ -2,6 +2,10 @@ modClDistPlotUI = function(id, label = "Plot Fractions WIthin Clusters") { ...@@ -2,6 +2,10 @@ modClDistPlotUI = function(id, label = "Plot Fractions WIthin Clusters") {
ns <- NS(id) ns <- NS(id)
tagList( tagList(
radioButtons(ns("rBAxisLabelsRotate"), "X-axis labels:",
c("horizontal" = 0,
"45deg" = 45,
"90 deg" = 90)),
actionButton(ns('butPlotClDist'), 'Plot!'), actionButton(ns('butPlotClDist'), 'Plot!'),
plotOutput(ns('outPlotClDist'), height = '800px', width = 'auto'), plotOutput(ns('outPlotClDist'), height = '800px', width = 'auto'),
downPlotUI(ns('downPlotClDist'), "Download PDF") downPlotUI(ns('downPlotClDist'), "Download PDF")
...@@ -45,11 +49,18 @@ modClDistPlot = function(input, output, session, in.data, in.cols = NULL, in.fna ...@@ -45,11 +49,18 @@ modClDistPlot = function(input, output, session, in.data, in.cols = NULL, in.fna
#limits = in.cols()$cl.no) #limits = in.cols()$cl.no)
loc.rads = as.numeric(input$rBAxisLabelsRotate) * pi / 180
loc.hjust = 0.5*(1-sin(loc.rads))
loc.vjust = 0.5*(1-cos(loc.rads))
p.out = p.out + p.out = p.out +
scale_y_continuous(labels = percent) + scale_y_continuous(labels = percent) +
ylab("percentage of cells\n") + ylab("percentage of cells\n") +
xlab("") + xlab("") +
ggplotTheme() ggplotTheme() +
theme(
axis.text.x = rotatedAxisElementText(as.numeric(input$rBAxisLabelsRotate))
)
#myGgplotTheme #myGgplotTheme
return(p.out) return(p.out)
......
...@@ -18,7 +18,7 @@ library(dendextend) # for color_branches ...@@ -18,7 +18,7 @@ library(dendextend) # for color_branches
library(colorspace) # for palettes (used to colour dendrogram) library(colorspace) # for palettes (used to colour dendrogram)
library(RColorBrewer) library(RColorBrewer)
# sparcl temporarily unavailable on CRAN # sparcl temporarily unavailable on CRAN
#library(sparcl) # sparse hierarchical and k-means library(sparcl) # sparse hierarchical and k-means
library(scales) # for percentages on y scale library(scales) # for percentages on y scale
library(dtw) # for dynamic time warping library(dtw) # for dynamic time warping
library(imputeTS) # for interpolating NAs library(imputeTS) # for interpolating NAs
......
...@@ -142,13 +142,13 @@ shinyUI(fluidPage( ...@@ -142,13 +142,13 @@ shinyUI(fluidPage(
tabPanel( tabPanel(
'Hierarchical', 'Hierarchical',
clustHierUI('tabClHier') clustHierUI('tabClHier')
) ),
# sparse hierarchical clustering package sparcl temporarily unavailable from CRAN # sparse hierarchical clustering package sparcl temporarily unavailable from CRAN
# tabPanel( tabPanel(
# 'Hierarchical Sparse', 'Hierarchical Sparse',
# clustHierSparUI('tabClHierSpar') clustHierSparUI('tabClHierSpar')
#) )
)) ))
) )
)) ))
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment