Background color in specific places ggplot2 boxplot [duplicate]2019 Community Moderator ElectionMake the background of a graph different colours in different regionsCustomize background to highlight ranges of data in ggplotSide-by-side plots with ggplot2Rotating and spacing axis labels in ggplot2OS X Terminal ColorsHow do I get the color from a hexadecimal color code using .NET?How to set limits for axes in ggplot2 R plots?Order Bars in ggplot2 bar graphGet color-int from color resourceIgnore outliers in ggplot2 boxplotEmulate ggplot2 default color paletteHex transparency in colors

How could a female member of a species produce eggs unto death?

Unreachable code, but reachable with exception

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

Potentiometer like component

My adviser wants to be the first author

Best mythical creature to use as livestock?

What has been your most complicated TikZ drawing?

Single word request: Harming the benefactor

It's a yearly task, alright

What is the likely impact on flights of grounding an entire aircraft series?

Am I not good enough for you?

Can "semicircle" be used to refer to a part-circle that is not a exact half-circle?

What does it mean when multiple 々 marks follow a 、?

Deleting missing values from a dataset

How does Dispel Magic work against Stoneskin?

Can the druid cantrip Thorn Whip really defeat a water weird this easily?

what does the apostrophe mean in this notation?

Examples of odd-dimensional manifolds that do not admit contact structure

When is a batch class instantiated when you schedule it?

How is the Swiss post e-voting system supposed to work, and how was it wrong?

Confusion with the nameplate of an induction motor

Best approach to update all entries in a list that is paginated?

What to do when during a meeting client people start to fight (even physically) with each others?

Co-worker team leader wants to inject the crap software product of his friends into our development. What should I say to our common boss?



Background color in specific places ggplot2 boxplot [duplicate]



2019 Community Moderator ElectionMake the background of a graph different colours in different regionsCustomize background to highlight ranges of data in ggplotSide-by-side plots with ggplot2Rotating and spacing axis labels in ggplot2OS X Terminal ColorsHow do I get the color from a hexadecimal color code using .NET?How to set limits for axes in ggplot2 R plots?Order Bars in ggplot2 bar graphGet color-int from color resourceIgnore outliers in ggplot2 boxplotEmulate ggplot2 default color paletteHex transparency in colors










0
















This question already has an answer here:



  • Make the background of a graph different colours in different regions

    2 answers



  • Customize background to highlight ranges of data in ggplot [duplicate]

    2 answers



I have the following code to plot some data using boxplot. I am looking to know how to plot some background color in the graph. For instance, it will be very good if I could plot grey color background between group 1 and 2. And dark grey color between group 16 and 18. I am appreciate any help. Regards.



dados <- read.table(text = 'subj var time group 
1: 0.9995127 PT 0
2: 0.9994366 PT 0
3: 0.9997657 PT 0
4: 0.9996991 PT 0
5: 0.9938514 T1 1
6: 0.9985952 T1 1
7: 0.9989975 T1 1
8: 0.9988476 T1 1
9: 0.9884567 T2 2
10: 0.998 T2 2
11: 0.9900545 T2 2
12: 0.9973228 T2 2
65: 0.9818935 POT1 16
66: 0.9196845 POT1 16
67: 0.8605142 POT1 16
68: 0.8620914 POT1 16
69: 0.9878192 POT2 17
70: 0.9826672 POT2 17
71: 0.9640381 POT2 17
72: 0.8976091 POT2 17
73: 0.9907579 POT3 18
74: 0.9922122 POT3 18
75: 0.9808981 POT3 18
76: 0.8988121 POT3 18', header = T)
library(ggplot2)
library(dplyr)
dados$group <- as.factor(dados$group)
head (dados)
p<-ggplot(dados, aes(x=group, y=var)) + geom_boxplot()
p + scale_x_discrete(breaks=c("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22"),labels=c("PT","T01", "T02","T03","T04","T05","T06","T07","T08","T09","T10","T11","T12","T13","T14","T15","POT1","POT2","POT3","POT4","POT5","POT6","POT7"))









share|improve this question















marked as duplicate by camille, markus, Rui Barradas r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 6 at 19:06


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















    0
















    This question already has an answer here:



    • Make the background of a graph different colours in different regions

      2 answers



    • Customize background to highlight ranges of data in ggplot [duplicate]

      2 answers



    I have the following code to plot some data using boxplot. I am looking to know how to plot some background color in the graph. For instance, it will be very good if I could plot grey color background between group 1 and 2. And dark grey color between group 16 and 18. I am appreciate any help. Regards.



    dados <- read.table(text = 'subj var time group 
    1: 0.9995127 PT 0
    2: 0.9994366 PT 0
    3: 0.9997657 PT 0
    4: 0.9996991 PT 0
    5: 0.9938514 T1 1
    6: 0.9985952 T1 1
    7: 0.9989975 T1 1
    8: 0.9988476 T1 1
    9: 0.9884567 T2 2
    10: 0.998 T2 2
    11: 0.9900545 T2 2
    12: 0.9973228 T2 2
    65: 0.9818935 POT1 16
    66: 0.9196845 POT1 16
    67: 0.8605142 POT1 16
    68: 0.8620914 POT1 16
    69: 0.9878192 POT2 17
    70: 0.9826672 POT2 17
    71: 0.9640381 POT2 17
    72: 0.8976091 POT2 17
    73: 0.9907579 POT3 18
    74: 0.9922122 POT3 18
    75: 0.9808981 POT3 18
    76: 0.8988121 POT3 18', header = T)
    library(ggplot2)
    library(dplyr)
    dados$group <- as.factor(dados$group)
    head (dados)
    p<-ggplot(dados, aes(x=group, y=var)) + geom_boxplot()
    p + scale_x_discrete(breaks=c("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22"),labels=c("PT","T01", "T02","T03","T04","T05","T06","T07","T08","T09","T10","T11","T12","T13","T14","T15","POT1","POT2","POT3","POT4","POT5","POT6","POT7"))









    share|improve this question















    marked as duplicate by camille, markus, Rui Barradas r
    Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Mar 6 at 19:06


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















      0












      0








      0









      This question already has an answer here:



      • Make the background of a graph different colours in different regions

        2 answers



      • Customize background to highlight ranges of data in ggplot [duplicate]

        2 answers



      I have the following code to plot some data using boxplot. I am looking to know how to plot some background color in the graph. For instance, it will be very good if I could plot grey color background between group 1 and 2. And dark grey color between group 16 and 18. I am appreciate any help. Regards.



      dados <- read.table(text = 'subj var time group 
      1: 0.9995127 PT 0
      2: 0.9994366 PT 0
      3: 0.9997657 PT 0
      4: 0.9996991 PT 0
      5: 0.9938514 T1 1
      6: 0.9985952 T1 1
      7: 0.9989975 T1 1
      8: 0.9988476 T1 1
      9: 0.9884567 T2 2
      10: 0.998 T2 2
      11: 0.9900545 T2 2
      12: 0.9973228 T2 2
      65: 0.9818935 POT1 16
      66: 0.9196845 POT1 16
      67: 0.8605142 POT1 16
      68: 0.8620914 POT1 16
      69: 0.9878192 POT2 17
      70: 0.9826672 POT2 17
      71: 0.9640381 POT2 17
      72: 0.8976091 POT2 17
      73: 0.9907579 POT3 18
      74: 0.9922122 POT3 18
      75: 0.9808981 POT3 18
      76: 0.8988121 POT3 18', header = T)
      library(ggplot2)
      library(dplyr)
      dados$group <- as.factor(dados$group)
      head (dados)
      p<-ggplot(dados, aes(x=group, y=var)) + geom_boxplot()
      p + scale_x_discrete(breaks=c("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22"),labels=c("PT","T01", "T02","T03","T04","T05","T06","T07","T08","T09","T10","T11","T12","T13","T14","T15","POT1","POT2","POT3","POT4","POT5","POT6","POT7"))









      share|improve this question

















      This question already has an answer here:



      • Make the background of a graph different colours in different regions

        2 answers



      • Customize background to highlight ranges of data in ggplot [duplicate]

        2 answers



      I have the following code to plot some data using boxplot. I am looking to know how to plot some background color in the graph. For instance, it will be very good if I could plot grey color background between group 1 and 2. And dark grey color between group 16 and 18. I am appreciate any help. Regards.



      dados <- read.table(text = 'subj var time group 
      1: 0.9995127 PT 0
      2: 0.9994366 PT 0
      3: 0.9997657 PT 0
      4: 0.9996991 PT 0
      5: 0.9938514 T1 1
      6: 0.9985952 T1 1
      7: 0.9989975 T1 1
      8: 0.9988476 T1 1
      9: 0.9884567 T2 2
      10: 0.998 T2 2
      11: 0.9900545 T2 2
      12: 0.9973228 T2 2
      65: 0.9818935 POT1 16
      66: 0.9196845 POT1 16
      67: 0.8605142 POT1 16
      68: 0.8620914 POT1 16
      69: 0.9878192 POT2 17
      70: 0.9826672 POT2 17
      71: 0.9640381 POT2 17
      72: 0.8976091 POT2 17
      73: 0.9907579 POT3 18
      74: 0.9922122 POT3 18
      75: 0.9808981 POT3 18
      76: 0.8988121 POT3 18', header = T)
      library(ggplot2)
      library(dplyr)
      dados$group <- as.factor(dados$group)
      head (dados)
      p<-ggplot(dados, aes(x=group, y=var)) + geom_boxplot()
      p + scale_x_discrete(breaks=c("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22"),labels=c("PT","T01", "T02","T03","T04","T05","T06","T07","T08","T09","T10","T11","T12","T13","T14","T15","POT1","POT2","POT3","POT4","POT5","POT6","POT7"))




      This question already has an answer here:



      • Make the background of a graph different colours in different regions

        2 answers



      • Customize background to highlight ranges of data in ggplot [duplicate]

        2 answers







      r ggplot2 colors






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 6 at 18:17









      markus

      14.3k11235




      14.3k11235










      asked Mar 6 at 17:37









      Thiago PetersenThiago Petersen

      31




      31




      marked as duplicate by camille, markus, Rui Barradas r
      Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 6 at 19:06


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by camille, markus, Rui Barradas r
      Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 6 at 19:06


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Is this close to what you are looking for?



          (Assumes you have done the dados data frame post-processing you have above)



          dados <-
          dados %>%
          mutate(
          xstart = as.factor(c(rep(1, nrow(.) / 2), rep(16, nrow(.) / 2))),
          xend = as.factor(c(rep(2, nrow(.) / 2), rep(18, nrow(.) / 2))),
          ystart = -Inf,
          yend = Inf
          )

          p <-
          ggplot(dados, aes(x = group, y = var)) +
          theme_bw() +
          geom_rect(
          aes(
          xmin = xstart,
          xmax = xend,
          ymin = ystart,
          ymax = yend,
          ),
          fill = c(rep("gray90", nrow(dados) / 2), rep("gray80", nrow(dados) / 2))
          ) +
          geom_boxplot() +
          scale_x_discrete(
          breaks = as.character(c(0:2, 16:18)),
          labels = c("PT", "T01", "T02", "POT1", "POT2", "POT3")
          )
          p


          Although, the darker gray, compromises a bit the visibility of the whiskers, at least in this case.






          share|improve this answer























          • Thanks, Maria! Your code helped me a lot =)

            – Thiago Petersen
            Mar 7 at 19:11

















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Is this close to what you are looking for?



          (Assumes you have done the dados data frame post-processing you have above)



          dados <-
          dados %>%
          mutate(
          xstart = as.factor(c(rep(1, nrow(.) / 2), rep(16, nrow(.) / 2))),
          xend = as.factor(c(rep(2, nrow(.) / 2), rep(18, nrow(.) / 2))),
          ystart = -Inf,
          yend = Inf
          )

          p <-
          ggplot(dados, aes(x = group, y = var)) +
          theme_bw() +
          geom_rect(
          aes(
          xmin = xstart,
          xmax = xend,
          ymin = ystart,
          ymax = yend,
          ),
          fill = c(rep("gray90", nrow(dados) / 2), rep("gray80", nrow(dados) / 2))
          ) +
          geom_boxplot() +
          scale_x_discrete(
          breaks = as.character(c(0:2, 16:18)),
          labels = c("PT", "T01", "T02", "POT1", "POT2", "POT3")
          )
          p


          Although, the darker gray, compromises a bit the visibility of the whiskers, at least in this case.






          share|improve this answer























          • Thanks, Maria! Your code helped me a lot =)

            – Thiago Petersen
            Mar 7 at 19:11















          0














          Is this close to what you are looking for?



          (Assumes you have done the dados data frame post-processing you have above)



          dados <-
          dados %>%
          mutate(
          xstart = as.factor(c(rep(1, nrow(.) / 2), rep(16, nrow(.) / 2))),
          xend = as.factor(c(rep(2, nrow(.) / 2), rep(18, nrow(.) / 2))),
          ystart = -Inf,
          yend = Inf
          )

          p <-
          ggplot(dados, aes(x = group, y = var)) +
          theme_bw() +
          geom_rect(
          aes(
          xmin = xstart,
          xmax = xend,
          ymin = ystart,
          ymax = yend,
          ),
          fill = c(rep("gray90", nrow(dados) / 2), rep("gray80", nrow(dados) / 2))
          ) +
          geom_boxplot() +
          scale_x_discrete(
          breaks = as.character(c(0:2, 16:18)),
          labels = c("PT", "T01", "T02", "POT1", "POT2", "POT3")
          )
          p


          Although, the darker gray, compromises a bit the visibility of the whiskers, at least in this case.






          share|improve this answer























          • Thanks, Maria! Your code helped me a lot =)

            – Thiago Petersen
            Mar 7 at 19:11













          0












          0








          0







          Is this close to what you are looking for?



          (Assumes you have done the dados data frame post-processing you have above)



          dados <-
          dados %>%
          mutate(
          xstart = as.factor(c(rep(1, nrow(.) / 2), rep(16, nrow(.) / 2))),
          xend = as.factor(c(rep(2, nrow(.) / 2), rep(18, nrow(.) / 2))),
          ystart = -Inf,
          yend = Inf
          )

          p <-
          ggplot(dados, aes(x = group, y = var)) +
          theme_bw() +
          geom_rect(
          aes(
          xmin = xstart,
          xmax = xend,
          ymin = ystart,
          ymax = yend,
          ),
          fill = c(rep("gray90", nrow(dados) / 2), rep("gray80", nrow(dados) / 2))
          ) +
          geom_boxplot() +
          scale_x_discrete(
          breaks = as.character(c(0:2, 16:18)),
          labels = c("PT", "T01", "T02", "POT1", "POT2", "POT3")
          )
          p


          Although, the darker gray, compromises a bit the visibility of the whiskers, at least in this case.






          share|improve this answer













          Is this close to what you are looking for?



          (Assumes you have done the dados data frame post-processing you have above)



          dados <-
          dados %>%
          mutate(
          xstart = as.factor(c(rep(1, nrow(.) / 2), rep(16, nrow(.) / 2))),
          xend = as.factor(c(rep(2, nrow(.) / 2), rep(18, nrow(.) / 2))),
          ystart = -Inf,
          yend = Inf
          )

          p <-
          ggplot(dados, aes(x = group, y = var)) +
          theme_bw() +
          geom_rect(
          aes(
          xmin = xstart,
          xmax = xend,
          ymin = ystart,
          ymax = yend,
          ),
          fill = c(rep("gray90", nrow(dados) / 2), rep("gray80", nrow(dados) / 2))
          ) +
          geom_boxplot() +
          scale_x_discrete(
          breaks = as.character(c(0:2, 16:18)),
          labels = c("PT", "T01", "T02", "POT1", "POT2", "POT3")
          )
          p


          Although, the darker gray, compromises a bit the visibility of the whiskers, at least in this case.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 6 at 18:30









          Maria KalimeriMaria Kalimeri

          16




          16












          • Thanks, Maria! Your code helped me a lot =)

            – Thiago Petersen
            Mar 7 at 19:11

















          • Thanks, Maria! Your code helped me a lot =)

            – Thiago Petersen
            Mar 7 at 19:11
















          Thanks, Maria! Your code helped me a lot =)

          – Thiago Petersen
          Mar 7 at 19:11





          Thanks, Maria! Your code helped me a lot =)

          – Thiago Petersen
          Mar 7 at 19:11





          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved