1
LDPE_ester_80 <- read.table(text="Time  Value   SampleID
0   0.043501842 PP_0m_3a
0   0.062837605 PP_virgin_1a
0   0.047448064 PP_virgin_1b
0   0.06169221  PP_virgin_2a
30  0.164727573 PP_1_mhnes_UV_1a
30  0.143102841 PP_1m_1a
30  0.172545413 PP_1_mhnes_UV_1b
30  0.169354044 PP_1m_2a
60  0.223527391 PP_2_mhnes_UV_1a
60  0.134201756 PP_2m_1b
60  0.177466856 PP_2_mhnes_UV_1b
60  0.194665864 PP_2m_3b
60  0.281681336 PP_2m_4b
90  0.41039937  PP_3m_1a
90  0.398709677 PP_3m_1b
90  0.339117621 PP_3m_2a
90  0.379362836 PP_3m_3b
120 0.601786493 PP_4m_1a
120 0.784720551 PP_4m_2b
120 0.58218528  PP_4m_3a
120 0.586435863 PP_4m_3b
150 1.008573326 PP_5m_1a
150 1.00662725  PP_5m_1b
150 0.435590375 PP_5m_3a
150 0.57474698  PP_5m_4a", header=TRUE)

After linear regression i found that the exponential model had the best fit. But in ggplot doesn't perform well. the model is the :

exp.model <-lm(log(Value) ~ Time, data=LDPE_ester_80) 

and the ggplot :

ggplot(LDPE_ester_80, aes(Time, Value) ) +
    geom_point() +   
    stat_smooth(method = lm, formula = log(y) ~ x, fill="mediumorchid4", colour="mediumorchid4", size=1.5, alpha = 0.2)+
    theme_classic() + 
    theme(text = element_text (family = "Calimbri", size = 12))+
    geom_point(shape=8, size=4, color="blue") + 
    ggtitle("exponetial regression") 

I am sure that the mistake is very simple to find but i haven't yet!

user20650
  • 24,654
  • 5
  • 56
  • 91
  • 5
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Since we can't see the plot i's not clear what the problem is when you say "ggplot doesn't perform well". – MrFlick Dec 14 '18 at 18:21
  • I cant load a picture yet ! My model has a Adjusted R-squared: 0.8869 . Ggplot in the other hand , doesnt show all the data in the y lebel, plus shows negatives values and all the values are possitive – Despina Barouta Dec 14 '18 at 18:35
  • 1
    What MrFlick is saying, is that without supplying any data, we can't replicate the plot. – Anonymous coward Dec 14 '18 at 19:15
  • 1
    sorry but iam new in the block. i tried to load my data in the right way – Despina Barouta Dec 14 '18 at 19:40

2 Answers2

2

stat_smooth works best if you use it with your actual y values. There's no way to run-log-transform the results automatically. It would be better just to plot log(Value) from the beginning.

ggplot(LDPE_ester_80, aes(Time, log(Value)) ) +
  geom_point() +   
  stat_smooth(method = lm, formula = y ~ x, fill="mediumorchid4", colour="mediumorchid4", size=1.5, alpha = 0.2)+
  theme_classic() + 
  theme(text = element_text (family = "Calimbri", size = 12))+
  geom_point(shape=8, size=4, color="blue") + 
  ggtitle("exponetial regression") 

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295
0

I cannot place an image in a comment, and so place it here. If you are interested in fitting the data without a log transform, I was able to fit the posted data to a sigmoidal type equation with two shape parameters a and b with an offset, y = 1.0 / (1.0 + exp(-1.0 * a * (x - b))) + offset with parameter values a = 2.7733501227846083E-02, b = 1.0879951192178710E+02 and Offset = 2.2490280017710324E-02 yielding RMSE = 0.117 and R-squared = 0.819 sigmoidal

massisenergy
  • 1,764
  • 3
  • 14
  • 25
James Phillips
  • 4,526
  • 3
  • 13
  • 11