Im trying to create a chart with points in which the mpg
will be displayed as a grey dot and qsec
as a green. The thing is that I want the 2 dots to be displayed like inner and outer circle. And of course their size should be analog to the value they display.
library(ggplot2)
library(plotly)
p <- mtcars%>%ggplot(aes(x=wt))
geom_point(aes(y=x,size=mpg*2),color="gray")
geom_point(aes(y=x,size=qsec),color="darkolivegreen")
scale_x_continuous(n.breaks=14)
theme(legend.position = 'none',
axis.title.y = element_blank(),
axis.text.y = element_blank())
labs(x="")
p
ggplotly(p)
CodePudding user response:
You haven't specified a y axis variable, so there is nothing to plot. At the moment your code throws an error because there is no variable called x
in mtcars
.
If, for example, you want hp
on the y axis, your code works as expected.
library(ggplot2)
library(plotly)
p <- mtcars %>% ggplot(aes(wt))
geom_point(aes(y = hp, size = mpg * 2), color = "gray")
geom_point(aes(y = hp, size = qsec), color = "darkolivegreen")
scale_x_continuous(n.breaks = 14)
theme(legend.position = 'none',
axis.title.y = element_blank(),
axis.text.y = element_blank())
labs(x = "")
ggplotly(p)