您好我有一个简单的闪亮应用程序,我在其中创建虹膜数据集中找到的变量的散点图。我想要的是能够以某种方式修改情节。首先,我希望能够为每个轴设置网格线的限制(例如1),然后将背景颜色设置为白色,将标记颜色设置为蓝色并添加趋势线。
首选款式:剧情标题 - Calibri(或类似),10 pt,粗体, 深灰色
轴标题 - Calibri light(或类似),16 pt,粗体,深灰色
轴编号标签 - Calibri,11 pt
我不知道ggplot2中是否所有这些或者某些都可以与plotly结合使用,或者我必须只使用它作为我的新手并且想要一些指导。谢谢
library(shiny)
library(ggplot2)
library(plotly)
fluidPage(
# App title ----
titlePanel(div("CROSS CORRELATION",style = "color:blue")),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
),
# Main panel for displaying outputs ----
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Correlation Plot",
fluidRow(
column(3, uiOutput("lx1")),
column(3,uiOutput("lx2"))),
plotlyOutput("sc"))
))
))
function(input, output) {
output$lx1<-renderUI({
selectInput("lx1", label = h4("Select 1st Expression Profile"),
choices = colnames(iris[,1:4]),
selected = "Lex1")
})
output$lx2<-renderUI({
selectInput("lx2", label = h4("Select 2nd Expression Profile"),
choices = colnames(iris[,1:4]),
selected = "Lex2")
})
output$sc<-renderPlotly({
p <- ggplot(iris, aes_string(x = input$lx1, y = input$lx2)) +
geom_point()
ggplotly(p) %>%
layout(height = 400)
})
}
答案 0 :(得分:1)
好的,抱歉延迟回复,但这是一个改变您请求的所有功能的工作示例。它涉及的比我领导的要多一些...... Calibri不是R内置的字体,因此需要使用font extra
包加载。然后,您想要更改的大多数选项在theme()
参数中都很简单,但悬停文本需要在plotly
调用选项中进行更改。希望这个例子有助于您的代码!
## Note: extrafont is a bit finnicky on Windows,
## so be sure to execute the code in the order
## provided, or else ggplot won't find the font
# Use this to acquire additional fonts not found in R
install.packages("extrafont");library(extrafont)
# Warning: if not specified in font_import, it will
# take a bit of time to get all fonts
font_import(pattern = "calibri")
loadfonts(device = "win")
# Load the packages
library(ggplot2)
library(plotly)
# Just use cars data frame
p <- ggplot(cars, aes(x = speed, y = dist)) +
# Change the point options in geom_point
geom_point(color = "darkblue") +
# Change the title of the plot (can change axis titles
# in this option as well and add subtitle)
labs(title = "Distance vs Speed") +
# Change where the tick marks are
scale_x_continuous(breaks = seq(0, 30, 2.5)) +
# Change how the text looks for each element
theme(title = element_text(family = "Calibri",
size = 10,
face = "bold"),
axis.title = element_text(family = "Calibri Light",
size = 16,
face = "bold",
color = "darkgrey"),
axis.text = element_text(family = "Calibri",
size = 11))
ggplotly(p) %>%
layout(hoverlabel = list(bgcolor = "white",
font = list(family = "Calibri",
size = 9,
color = "black")))