Testing Observable

Published

September 25, 2023

Plot 1

library('tidyverse')
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.2     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
glimpse(iris)
Rows: 150
Columns: 5
$ Sepal.Length <dbl> 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.…
$ Sepal.Width  <dbl> 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.…
$ Petal.Length <dbl> 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.5, 1.5, 1.…
$ Petal.Width  <dbl> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.…
$ Species      <fct> setosa, setosa, setosa, setosa, setosa, setosa, setosa, s…
summary(iris)
  Sepal.Length    Sepal.Width     Petal.Length    Petal.Width   
 Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100  
 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300  
 Median :5.800   Median :3.000   Median :4.350   Median :1.300  
 Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199  
 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800  
 Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500  
       Species  
 setosa    :50  
 versicolor:50  
 virginica :50  
                
                
                
iris_new <- tibble(species = iris$Species, 
                   sepal_length = iris$Sepal.Length,
                   sepal_width = iris$Sepal.Width)
write_csv(iris_new, file = 'iris.csv')
data = FileAttachment("iris.csv").csv({ typed: true })
data = Array(150) [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, …]
viewof sepal_length_min = Inputs.range(
  [5, 10], 
  {value: 5, step: 1, label: "Sepal length min:"}
)
sepal_length_min = 5
filtered = data.filter(function(iris) {
  return sepal_length_min < iris.sepal_length;
})
filtered = Array(118) [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, …]
Plot.rectY(filtered, 
  Plot.binX(
    {y: "count"}, 
    {x: "sepal_length", fill: "species"}
  ))
  .plot({
    facet: {
      data: filtered,
      x: "species",
      y: "sepal_length",
      marginRight: 80
    },
    marks: [
      Plot.frame(),
    ]
  }
)
5.15.25.35.45.55.65.75.85.966.16.26.36.46.56.66.76.86.977.17.27.37.47.67.77.9sepal_lengthsetosaversicolorvirginicaspecies050505050505050505050505050505050505050505050505050505↑ Frequency68686868686868sepal_length →

Plot 2

Plot.plot({
  marks: [
    Plot.dot(penguins, {x: "culmen_length_mm", y: "culmen_depth_mm", stroke: "species"}), // try changing "stroke" to "fill"
    Plot.linearRegressionY(penguins, {x: "culmen_length_mm", y: "culmen_depth_mm", stroke: "species"})
  ],
  ariaLabel: "Penguin culmen dimensions",
  ariaDescription: "Scatterplot of culmen length by culmen depth for three penguin species. Linear trendlines are added to each, revealing similar positive linear trends between culmen length and depth for chinstrap, gentoo and Adelie penguins."
})
1415161718192021↑ culmen_depth_mm3540455055culmen_length_mm →