简体   繁体   中英

Issue with linestyle in legend while ploting 2 datasets in ggplot2 scatter plot

I would like to compare some numerical analysis results with analytical solution in a plot using ggplot2. I am plotting analytical solution with a continuous solid line and numerical solution with dots. The only issue is in the legend, where a line is displayed for the numerical results (FVM). I only want a circle to be displayed in the legend for "FVM" not the line and circle. Would you please help? here are my script and plot:

library(ggplot2)
xa <- seq(0, 1, by = .01)
phia<- -(exp(2.5*xa/0.1)-1)/(exp(2.5/0.1)-1)+1
anal.dat <-data.frame(x=xa,y=phia)
xc <- c (0.258065 , 0.645161 , 0.83871 , 0.935484 , 0.983871)
phic <- c (0.99869, 0.984046, 0.905865, 0.677627, 0.287415)
cfd.data <- data.frame(x=xc,T=phic)
p <- ggplot(data=NULL)
p + geom_line(data=anal.dat, aes(x, y,colour="Analytical"),size = 1) + geom_point(data=cfd.data,aes(x, T,colour="FVM"),size = 4,shape=16) + theme_bw() + labs(x = "x",y=expression(phi)) + scale_colour_manual(name='', values=c('Analytical'='deepskyblue','FVM'='firebrick1'))

在此处输入图片说明

Use guide_legend to override the current legend.

p + geom_line(data=anal.dat, aes(x, y,colour="Analytical"),size = 1) +
  geom_point(data=cfd.data,aes(x, T,colour="FVM"),size = 4,shape=16) +
  theme_bw() + labs(x = "x",y=expression(phi)) +
  scale_colour_manual(name='', values=c('Analytical'='deepskyblue','FVM'='firebrick1')) +
  guides(colour = guide_legend(override.aes = list(shape = c(NA, 19), linetype = c("solid", "blank"))))

The output is 产量

Here is the list of symbols numbers (I used 19).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM