#plotly
library(plotly)
## Загрузка требуемого пакета: ggplot2
## Warning: пакет 'ggplot2' был собран под R версии 4.2.1
## 
## Присоединяю пакет: 'plotly'
## Следующий объект скрыт от 'package:ggplot2':
## 
##     last_plot
## Следующий объект скрыт от 'package:stats':
## 
##     filter
## Следующий объект скрыт от 'package:graphics':
## 
##     layout
library(dplyr)
## 
## Присоединяю пакет: 'dplyr'
## Следующие объекты скрыты от 'package:stats':
## 
##     filter, lag
## Следующие объекты скрыты от 'package:base':
## 
##     intersect, setdiff, setequal, union
data2 <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv")

plot_ly(type = 'violin') %>%   layout(xaxis = list(title = ""), yaxis = list(title = "", zeroline = F), title = "Распределение ВВП на душу населения по странам") %>% 
  add_trace(data = data2, x = ~continent[data2$country == "Switzerland"],
            y = ~gdpPercap[data2$country == "Switzerland"],
            legendgroup = 'Yes', scalegroup = 'Yes',
            name = 'Switzerland',
            side = 'negative',box = list(visible = T),
            meanline = list(visible = T),
            color = I("darkblue")) %>% 
  add_trace(data = data2, x = ~continent[data2$country == "Netherlands"],
            y = ~gdpPercap[data2$country == "Netherlands"],
            legendgroup = 'No', scalegroup = 'No',
            name = 'Netherlands',
            side = 'positive',box = list(visible = T),
            meanline = list(visible = T),
            color = I("darkred")) %>% 
  add_trace(data = data2, x = ~continent[data2$country == "Japan"],
            y = ~gdpPercap[data2$country == "Japan"],
            legendgroup = 'No', scalegroup = 'No',
            name = 'Japan',
            side = 'positive',box = list(visible = T),
            meanline = list(visible = T),
            color = I("purple")) %>% 
  add_trace(data = data2, x = ~continent[data2$country == "Hong Kong, China"],
            y = ~gdpPercap[data2$country == "Hong Kong, China"],
            legendgroup = 'Yes', scalegroup = 'Yes',
            name = 'Hong Kong, China',
            side = 'negative',box = list(visible = T),
            meanline = list(visible = T),
            color = I("orange")) 
## Warning: Can't display both discrete & non-discrete data on same axis