[R] plotly

Thomas Subia tg@77m @end|ng |rom y@hoo@com
Wed Jul 26 04:04:59 CEST 2023


 Colleagues,
Here is my reproducible code.
library(plotly)

t <- list(
  family = "Arial",
  size = 12,
  color = "black",
  face="bold")


t3 <- list(
  family = "Arial",
  size = 12,
  color = "black",
  face="bold")

t5 <- list(
  family = "Arial",
  size = 12,
  color = "black",
  face="bold")

plot_ly(
  domain = list(x = c(0, .5), y = c(0,0.5)),
  value = 319,
  title = list(text = "Example\n4,800 Target",font=t),
  type = "indicator",
  mode = "gauge+number+delta",
  number = list(valueformat = "%.2f",font=t5), 
  delta = list(reference = 4800, valueformat = "%.2f",font=t3),
  gauge = list(
    axis = list(range = list(NULL, 9600), 
                tickfont = list(size = 12, face="bold",family = "Arial")),
    bar = list(color = "black"),
    steps = list(
      list(range = c(0, 4800), color = 'AAFF00'),
      list(range = c(4800, 9600), color = 'ffb2b2')),
    threshold = list(
      line = list(color = "black", width = 8),
      thickness = 0.75,
      value = 4800)))
Question 1:How can I save the plotly graph with a specific graph size?Using ggsave, one can define the height, width and unit of measure, is there something similar in plotly?Since I am creating the same gauge plot but with different data, I'd like all the resulting graphs to have the same size. I've googled this but to no avail,
Question 2:How can I adjust the tick marks of the gauge? Ideally the tick marks should be set at seq(0,9600,1200)
Thanks everyone!
Thomas Subia

    On Saturday, July 22, 2023 at 08:10:52 AM PDT, Boris Steipe <boris.steipe using utoronto.ca> wrote:  
 
 ChatGPT-4:

------ Query:  ----------------------------------

Thank you. The `value` in the code example is 2874. The plot shows a large number at the center and a smaller value computed as a delta relative to the `reference` of 4800. But the large value is given as 2870, and the smaller value is given as -1930 i.e. both values are rounded. Can I control the precision of these two numbers?


------ Response:  -------------------------------

In Plotly, you can control the precision of the numbers by specifying the `valueformat` and `delta.valueformat` parameters. These parameters accept a string in the format that is used by the C `printf` function. For example, `%.2f` specifies a number with two digits after the decimal point. Here is an example:

```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",
  number = list(valueformat = "%.2f"), 
  delta = list(reference = 4800, valueformat = "%.2f"),
  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)))
```
In this example, both the main number and the delta value will be displayed with two decimal places. You can adjust these strings to display the numbers with the precision you prefer.

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

Here you go. I have no idea how it does this, and have a discussion on elements of "Sein und Zeit" and book 19 of the Odyssey, and tutor me in Italian conversation, and draft Mermaid mind-maps - but here we are.


:-)






> 
> \In this example, the value was 2324, the gauge displays 2320.
> I'm not sure why this occurs. Changing the statement to 56, results in the gauge reading 60. I'm not sure what needs to be changed in the script or the environment to stop rounding.




> On Jul 22, 2023, at 10:43, Boris Steipe <boris.steipe using utoronto.ca> wrote:
> 
> What do you mean "Rounded"?
> What do you expect, what do you get instead?
> 
> ?
> 
> 
> 
> 
> 
>> On Jul 22, 2023, at 10:40, Thomas Subia via R-help <r-help using r-project.org> wrote:
>> 
>> Colleagues,
>> Thanks for the update.
>> My colleagues at work have run this script but the resulting graph output for value is rounded. How can one turn this annoying feature off?
>> I've googled this but to no avail.
>> 
>> 
>> 
>> 
>> [[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.

  
	[[alternative HTML version deleted]]



More information about the R-help mailing list