Report con OJS

Author

DV

Un esempio grafico in R

library(gapminder)
library(tidyverse)
gap_last <- gapminder |> 
  filter(year == 2007, continent != "Oceania") |> 
  mutate(continent = as.character(continent))
gap_last |> 
#  filter(continent == "Europe") |> 
  ggplot() +
    aes(x = gdpPercap, y = lifeExp) +
    geom_point() +
    labs(title = "Scatterplot gdpPercap vs lifeExp",
         x = "Gross Domestic Product (per capite)",
         y = "Life Expectancy (years)")

Lo stesso esempio in OJS

Questo è un banale codice ottenuto sfruttando OJS:

2 + 2
ojs_define(gap_last = gap_last |> transpose())
Plot.plot({
  title: "Scatterplot gdpPercap vs lifeExp",
  marginLeft: 56,  // per lasciare spazio alle etichette dell'asse Y
  marks: [
    Plot.dot(gap_last, {
      x: "gdpPercap",
      y: "lifeExp",
      r: 3,           // raggio dei punti
      fill: "#1f77b4" // colore
    })
  ],
  x: {label: "Gross Domestic Product (per capite)"},
  y: {label: "Life Expectancy (years)"}
})
viewof color = Inputs.select(["red", "orange", "yellow", "green", "blue", "violet"], {value: "green"})
continents = Array.from(new Set(gap_last.map(d => d.continent)))

// Crea la casella a discesa con i valori unici
viewof continent = Inputs.select(continents, {label: "Seleziona continente", value: continents[0]})
gap_continent = gap_last.filter(d => d.continent === continent)
Plot.plot({
  title: "Scatterplot gdpPercap vs lifeExp",
  marginLeft: 56,  // per lasciare spazio alle etichette dell'asse Y
  marks: [
    Plot.dot(gap_continent, {
      x: "gdpPercap",
      y: "lifeExp",
      r: 3,           // raggio dei punti
      fill: "#1f77b4" // colore
    })
  ],
  x: {label: "Gross Domestic Product (per capite)"},
  y: {label: "Life Expectancy (years)"}
})