Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 创建具有特定网格线、标记颜色、背景颜色和特定字体的生动且有光泽的反应性绘图_R_Ggplot2_Shiny_Plotly - Fatal编程技术网

R 创建具有特定网格线、标记颜色、背景颜色和特定字体的生动且有光泽的反应性绘图

R 创建具有特定网格线、标记颜色、背景颜色和特定字体的生动且有光泽的反应性绘图,r,ggplot2,shiny,plotly,R,Ggplot2,Shiny,Plotly,您好,我有一个简单的闪亮应用程序,我在其中创建了iris数据集中变量的散点图。我想要的是能够以某种方式修改绘图。首先,我希望能够为每个轴设置网格线的限制(例如,1),然后将背景颜色设置为白色,标记颜色设置为蓝色,并添加趋势线 首选样式:绘图标题-Calibri(或类似),10磅,粗体, 深灰色 轴标题-Calibri light(或类似),16磅,粗体,深灰色 轴编号标签–Calibri,11磅 数据标签–Calibri,9磅,黑色 数据标记-暗 蓝色圆圈 我不知道ggplot2中是否提供了所有

您好,我有一个简单的闪亮应用程序,我在其中创建了iris数据集中变量的散点图。我想要的是能够以某种方式修改绘图。首先,我希望能够为每个轴设置网格线的限制(例如,1),然后将背景颜色设置为白色,标记颜色设置为蓝色,并添加趋势线

  • 首选样式:绘图标题-Calibri(或类似),10磅,粗体, 深灰色

  • 轴标题-Calibri light(或类似),16磅,粗体,深灰色

  • 轴编号标签–Calibri,11磅

  • 数据标签–Calibri,9磅,黑色
  • 数据标记-暗 蓝色圆圈
  • 我不知道ggplot2中是否提供了所有这些或一些与plotly结合使用的功能,或者我只需要使用plotly,因为我对plotly不熟悉,需要一些指导。谢谢

    用户界面 服务器.r
    功能(输入、输出){
    
    输出$lx1好的,很抱歉延迟了响应,但这里有一个工作示例,可以更改您请求的所有功能。它比我介绍的要复杂一些……Calibri不是内置在R中的字体,所以需要使用包加载它。然后,您想要更改的大多数选项在参数中都很简单,但不是需要在看涨期权中更改悬停文本。希望此示例对您的代码有所帮助

    ## 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")))
    
    ##注意:extrafont在Windows上有点过时,
    ##因此,请确保按顺序执行代码
    ##提供,否则ggplot将找不到字体
    #使用此选项可获取R中未找到的其他字体
    安装程序包(“extrafont”);库(extrafont)
    #警告:如果在字体导入中未指定,它将
    #花点时间获取所有字体
    font\u导入(pattern=“calibri”)
    loadfonts(device=“win”)
    #加载包
    图书馆(GG2)
    图书馆(绘本)
    #仅使用cars数据帧
    p%
    布局(hoverlabel=list(bgcolor=“白色”,
    font=list(family=“Calibri”,
    尺寸=9,
    color=“黑色”)))
    
    通过快速搜索,plotly将允许在plotly输出中显示在
    ggplot
    中设置的所有基本主题选项。您正在考虑的所有选项都将通过
    ggplot
    主题()
    语句。请参见此处以供参考:…希望这有帮助!它有一些东西,但不是我需要的。我认为我应该只使用plotly而不是ggplot2。无论如何,感谢通过
    ggplot
    的主题?所有这些选项都可以更改。
    fontface
    可以设置为粗体,
    family
    可以用来更改字体,
    color
    可用于更改字体颜色,数据点形状和颜色可在
    几何点()内更改
    option等…如果您愿意,我可以复制一个不相关的绘图,显示其中一些选项。如果您愿意,我会很有帮助!我可以更改网格线限制吗?例如,不是0-2-4-6-8,而是0-1-2-3-4-5-6-7-8。因此,使用尽可能多的这些选项进行复制将是一个伟大而完整的答案,我将接受它!一个任务ion..这是一个小细节,但如何将绘图的默认灰色背景从灰色更改为白色,以及将网格线从白色更改为灰色?
    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) 
    
      })
    
    }
    
    ## 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")))