Skip to content

Instantly share code, notes, and snippets.

@srvanderplas
Created January 6, 2015 00:35
Show Gist options
  • Save srvanderplas/7645b4bb038729d72585 to your computer and use it in GitHub Desktop.
Save srvanderplas/7645b4bb038729d72585 to your computer and use it in GitHub Desktop.
Working Example of Unicode Issue with ggplot2 and shiny
library(shiny)
library(ggplot2)
# library(Cairo)
# options(shiny.usecairo=T)
# Define colors and shapes
colors <- c("#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd",
"#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf")
shapes1 <- c(1,0,3,4,8,5,2,6,-0x25C1, -0x25B7)
shapes2 <- 1:10
shinyServer(function(input, output, session){
output$plot <- renderPlot({
dd <- data.frame(x=1:10, y=0, grp = 1:10, color=colors, shape=ifelse(input$unicode=="unicode", shapes1, shapes2))
ggplot(data=dd, aes(x=x, y=y, shape=factor(grp))) +
geom_point(size=6) + coord_fixed(ratio=1) +
scale_shape_manual(values=list(shapes2, shapes1)[[(input$unicode=="unicode")+1]], guide="none") +
theme(axis.text=element_blank(), axis.ticks=element_blank(), axis.title=element_blank())
})
})
library(shiny)
seed <- runif(1, 1000, 1000000)
shinyUI(fluidPage(
titlePanel("Demonstration - Unicode Characters"),
fluidRow(
column(
2,
wellPanel(
radioButtons("unicode", "CharacterType", choices=c("Unicode"="unicode", "R Default"="normal"))
)
),
column(10,
div(align="center", plotOutput("plot"))
)
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment