0

I wonder if it is possible to create this kind of plots with R (ideally with ggplot2):

enter image description here

The black line is a exponential function following a equation y = A exp(Bx^0.5 - Cx^3), and the straight lines are just of the form y=b_0+b_1x, with differents slopes and intercepts.

I know the parameters of all those equations, but I do not know how to build that plor (made in Excel) with ggplot2.

1

1 Answer 1

0

For ggplot to work you have to put all the data of interest into a dataframe with a column denoting the category of each line- to distinguish the different colors. Here is how I would do it (code not tested- so you may have to fiddle around with it):

x=1:1000
A=...
B=...
C=...
exponential_eqn_data=data.frame(y=A*exp((B*x)**0.5 - (C*x)**3),x=x,category=paste0('exponential'))
b0=...
b1=...
straight_line_data=data.frame(y=b0+b1*x,x=x,category=paste0('straight line'))

data_plot=rbind(exponential_eqn_data,straight_line_data) #put these all in one data set

#Now plot
library(ggplot2)
plot=ggplot(data,aes(x=x,y=y,col=category))+geom_point()+geom_line()

print(plot)

#Or if you are not working in Rstudio

png('plot.png')
print(plot)
dev.off()
#then open plot.png manually

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.