[R] plotly question

Boris Steipe bor|@@@te|pe @end|ng |rom utoronto@c@
Sat Jul 22 00:04:15 CEST 2023


Since it is 2023, I asked that question to ChatGPT-4 and got the following response.

-------------------------

The `plotly` library in R uses the `gauge` argument inside the `plot_ly` function to specify the properties of the gauge plot. You can change the indicator color of the arc (also known as the bar) by setting the `bar` property inside `gauge`, and the `font` property for modifying the typeface and font size of the tick marks on the arc.

Below is an example that modifies your code to change the indicator color of the arc to blue and sets the font to Arial with a size of 20:

```R
plotly::plot_ly(
  domain = list(x = c(0, 1), y = c(0, 1)),
  value = 2874,
  title = list(text = "Generic"),
  type = "indicator",
  mode = "gauge+number+delta",
  delta = list(reference = 4800),
  gauge = list(
    axis = list(range = list(NULL, 5000), 
                tickfont = list(size = 20, family = "Arial")),
    bar = list(color = "blue"),
    steps = list(
      list(range = c(0, 4800), color = "white"),
      list(range = c(4800, 6000), color = "red")),
    threshold = list(
      line = list(color = "black", width = 6),
      thickness = 0.75,
      value = 4800)))
```

Please note that the colors are specified by strings that can either be a CSS-acceptable color name or a hexadecimal color code. You can adjust the `tickfont` size and family properties according to your preferences.

---------------

That seems to do what was requested - the bar is blue now, and changing "Arial" to "Times" in the code indeed has the expected effect.

Nice.




Boris





> On Jul 21, 2023, at 17:43, Jeff Newmiller <jdnewmil using dcn.davis.ca.us> wrote:
> 
> plotly is _not_ associated with posit. I think you are unlikely to find expertise with plotly in their forums. You might find help at stackoverflow.com.
> 
> On July 21, 2023 1:40:49 PM PDT, Bert Gunter <bgunter.4567 using gmail.com> wrote:
>> As you apparently haven't received any responses yet, I'll try to
>> suggest something useful. However, I have absolutely zero experience
>> with plotly, so this is just from general principles and reading the
>> plot_ly Help file, which says for the "..." arguments:
>> 
>> "Arguments (i.e., attributes) passed along to the trace type. See
>> schema() for a list of acceptable attributes for a given trace type
>> (by going to traces -> type -> attributes). Note that attributes
>> provided at this level may override other arguments (e.g. plot_ly(x =
>> 1:10, y = 1:10, color = I("red"), marker = list(color = "blue")))."
>> 
>> So I would **guess** that you needs to go to ?schema to see if the
>> further attributes of your "gauge" type that you wish to change are
>> there.
>> 
>> Alternatively, plotly is a package from posit.co, formerly RStudio;
>> they have an extensive support site and community here:
>> https://posit.co/support/
>> So you may have success there.
>> 
>> Finally, I assume you have tried web searching appropriate search
>> queries, but if not, you should do so. It is sometimes surprising how
>> much you can find that way.
>> 
>> ... and, again, apologies if my ignorance means my suggestions are useless.
>> 
>> Cheers,
>> Bert
>> 
>> 
>> On Fri, Jul 21, 2023 at 6:19 AM Thomas Subia via R-help
>> <r-help using r-project.org> wrote:
>>> 
>>> Colleagues
>>> 
>>> Here is my reproducible code
>>> 
>>> plot_ly(
>>>  domain = list(x = c(0, 1), y = c(0, 1)),
>>>  value = 2874,
>>>  title = list(text = "Generic"),
>>>  type = "indicator",
>>>  mode = "gauge+number+delta",
>>>  delta = list(reference = 4800),
>>>  gauge = list(
>>>    axis =list(range = list(NULL, 5000)),
>>>    steps = list(
>>>    list(range = c(0, 4800), color = "white"),
>>>    list(range = c(4800, 6000), color = "red")),
>>>    threshold = list(
>>>    line = list(color = "black", width = 6),
>>>    thickness = 0.75,
>>>    value = 4800)))
>>> 
>>> How can I change the indicator color from green to some other color?
>>> 
>>> How can I change the typeface and font size of the speedometer tick mark font size?
>>> 
>>> Thomas Subia
>>> 
>>>        [[alternative HTML version deleted]]
>>> 
>>> ______________________________________________
>>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> -- 
> Sent from my phone. Please excuse my brevity.
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list