Some changes in a bubbleplot (ggplot)

2019-08-14 23:58发布

I need some changes to this plot: enter image description here

library(ggplot2)    # load ggplot2 plotting package

x_var <- rnorm( n = 15, mean = 5, sd = 2)
y_var <- x_var + rnorm(n = 15, mean = 5, sd =4)
size_var <- runif(15, 1,10)

df.test_data <- data.frame(x_var, y_var, size_var)'

ggplot(data=df.test_data, aes(x=x_var, y=y_var)) +
    geom_point(aes(size=(size_var))) 

I'm asking:

  1. How can I change the title of the legend?
  2. How can I give to the points a color scale that changes with the value of the point (from yellow to red, yellow for values near to 2, red for values near to 7)

标签: r ggplot2
1条回答
倾城 Initia
2楼-- · 2019-08-15 00:27

Is that what you want?

ggplot(data=dfx.test_data, aes(x=x_var, y=y_var)) +geom_point(aes(size=(size_var),color=size_var))+scale_color_gradient(low="yellow", high="red")+labs(colour="NEW TITLE")

enter image description here

查看更多
登录 后发表回答