Barplot label subscripts without using expression












4















I have seen several topics on creating subscripts on barplots, but I cannot seem to get the function "expression" to work in my code. I have attached the code below ideally I want $K_a$, $N_{max}$, $C_{r50}$, $C_{s50}$, but I cannot figure out how to make that appear in the bargraph. There's a large likelihood I have coded the most in-efficient bar graph, so any suggestions would be appreciated!



library(ggplot2)

lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)

lowdoseparams <-c("V", "k", "ka", "u03B1", "u03B3", "u03B7", "u03C3", "Nmax", "Cs50", "Cr50")
#lowdoseparams <-expression(V, k, k_a, alpha, gamma, eta, sigma, Nmax, Cs50, Cr50)

lowdata <- data.frame(Parameters=lowdoseparams, Effects=lowdose)
p_low<-ggplot(data=lowdata, aes(x=Parameters, y=Effects)) +
geom_bar(stat="identity")+theme(axis.text=element_text(size=14),
axis.title=element_text(size=18))
p_low









share|improve this question























  • Currently when you plot the bar graph, the bar label is "ka" I want to know how to do "$k_a$" so the a is subscript.

    – PonyMath
    Nov 19 '18 at 17:48
















4















I have seen several topics on creating subscripts on barplots, but I cannot seem to get the function "expression" to work in my code. I have attached the code below ideally I want $K_a$, $N_{max}$, $C_{r50}$, $C_{s50}$, but I cannot figure out how to make that appear in the bargraph. There's a large likelihood I have coded the most in-efficient bar graph, so any suggestions would be appreciated!



library(ggplot2)

lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)

lowdoseparams <-c("V", "k", "ka", "u03B1", "u03B3", "u03B7", "u03C3", "Nmax", "Cs50", "Cr50")
#lowdoseparams <-expression(V, k, k_a, alpha, gamma, eta, sigma, Nmax, Cs50, Cr50)

lowdata <- data.frame(Parameters=lowdoseparams, Effects=lowdose)
p_low<-ggplot(data=lowdata, aes(x=Parameters, y=Effects)) +
geom_bar(stat="identity")+theme(axis.text=element_text(size=14),
axis.title=element_text(size=18))
p_low









share|improve this question























  • Currently when you plot the bar graph, the bar label is "ka" I want to know how to do "$k_a$" so the a is subscript.

    – PonyMath
    Nov 19 '18 at 17:48














4












4








4


1






I have seen several topics on creating subscripts on barplots, but I cannot seem to get the function "expression" to work in my code. I have attached the code below ideally I want $K_a$, $N_{max}$, $C_{r50}$, $C_{s50}$, but I cannot figure out how to make that appear in the bargraph. There's a large likelihood I have coded the most in-efficient bar graph, so any suggestions would be appreciated!



library(ggplot2)

lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)

lowdoseparams <-c("V", "k", "ka", "u03B1", "u03B3", "u03B7", "u03C3", "Nmax", "Cs50", "Cr50")
#lowdoseparams <-expression(V, k, k_a, alpha, gamma, eta, sigma, Nmax, Cs50, Cr50)

lowdata <- data.frame(Parameters=lowdoseparams, Effects=lowdose)
p_low<-ggplot(data=lowdata, aes(x=Parameters, y=Effects)) +
geom_bar(stat="identity")+theme(axis.text=element_text(size=14),
axis.title=element_text(size=18))
p_low









share|improve this question














I have seen several topics on creating subscripts on barplots, but I cannot seem to get the function "expression" to work in my code. I have attached the code below ideally I want $K_a$, $N_{max}$, $C_{r50}$, $C_{s50}$, but I cannot figure out how to make that appear in the bargraph. There's a large likelihood I have coded the most in-efficient bar graph, so any suggestions would be appreciated!



library(ggplot2)

lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)

lowdoseparams <-c("V", "k", "ka", "u03B1", "u03B3", "u03B7", "u03C3", "Nmax", "Cs50", "Cr50")
#lowdoseparams <-expression(V, k, k_a, alpha, gamma, eta, sigma, Nmax, Cs50, Cr50)

lowdata <- data.frame(Parameters=lowdoseparams, Effects=lowdose)
p_low<-ggplot(data=lowdata, aes(x=Parameters, y=Effects)) +
geom_bar(stat="identity")+theme(axis.text=element_text(size=14),
axis.title=element_text(size=18))
p_low






r ggplot2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 16:34









PonyMathPonyMath

261




261













  • Currently when you plot the bar graph, the bar label is "ka" I want to know how to do "$k_a$" so the a is subscript.

    – PonyMath
    Nov 19 '18 at 17:48



















  • Currently when you plot the bar graph, the bar label is "ka" I want to know how to do "$k_a$" so the a is subscript.

    – PonyMath
    Nov 19 '18 at 17:48

















Currently when you plot the bar graph, the bar label is "ka" I want to know how to do "$k_a$" so the a is subscript.

– PonyMath
Nov 19 '18 at 17:48





Currently when you plot the bar graph, the bar label is "ka" I want to know how to do "$k_a$" so the a is subscript.

– PonyMath
Nov 19 '18 at 17:48












2 Answers
2






active

oldest

votes


















3














Using this question as referenece: Subscript letters in ggplot axis label



Here is a solution using the expression function to create the x axis labels:



library(ggplot2)

lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)
lowdoseparams <-c("V", "k", "k[a]", "u03B1", "u03B3", "u03B7", "u03C3", "N[max]", "Cs50", "Cr50")

#define the lowdoseparams as factors in the same order as the labels
lowdoseparams<-factor(lowdoseparams, levels =lowdoseparams)
#create the labels
xlabels<-expression(V, k, k['a'], alpha, gamma, eta, sigma, N[max], Cs[50], Cr[50])

lowdata <- data.frame(Parameters=lowdoseparams, Effects=lowdose)
p_low<-ggplot(data=lowdata, aes(x=Parameters, y=Effects)) +
geom_bar(stat="identity")+
theme(axis.text=element_text(size=14),axis.title=element_text(size=18)) +
scale_x_discrete(labels= xlabels)
p_low


Looks like the xlabels vector of type "expression" cannot be added to the dataframe but must remain as an independent vector.



enter image description here






share|improve this answer

































    1














    I guess you can use this unicode subscript lookup table. For example U2090 is for a





    library(ggplot2)

    lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)
    lowdoseparams <- c("V", "k", "kU2090", "u03B1", "u03B3", "u03B7", "u03C3", "Nmax", "Cs50", "Cr50")
    lowdata <- data.frame(Parameters = lowdoseparams, Effects = lowdose)

    p_low <- ggplot(data = lowdata, aes(x = Parameters, y = Effects)) +
    geom_col() +
    theme(
    axis.text = element_text(size = 14),
    axis.title = element_text(size = 18)
    )
    p_low




    Created on 2018-11-19 by the reprex package (v0.2.1.9000)






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379014%2fbarplot-label-subscripts-without-using-expression%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      Using this question as referenece: Subscript letters in ggplot axis label



      Here is a solution using the expression function to create the x axis labels:



      library(ggplot2)

      lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)
      lowdoseparams <-c("V", "k", "k[a]", "u03B1", "u03B3", "u03B7", "u03C3", "N[max]", "Cs50", "Cr50")

      #define the lowdoseparams as factors in the same order as the labels
      lowdoseparams<-factor(lowdoseparams, levels =lowdoseparams)
      #create the labels
      xlabels<-expression(V, k, k['a'], alpha, gamma, eta, sigma, N[max], Cs[50], Cr[50])

      lowdata <- data.frame(Parameters=lowdoseparams, Effects=lowdose)
      p_low<-ggplot(data=lowdata, aes(x=Parameters, y=Effects)) +
      geom_bar(stat="identity")+
      theme(axis.text=element_text(size=14),axis.title=element_text(size=18)) +
      scale_x_discrete(labels= xlabels)
      p_low


      Looks like the xlabels vector of type "expression" cannot be added to the dataframe but must remain as an independent vector.



      enter image description here






      share|improve this answer






























        3














        Using this question as referenece: Subscript letters in ggplot axis label



        Here is a solution using the expression function to create the x axis labels:



        library(ggplot2)

        lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)
        lowdoseparams <-c("V", "k", "k[a]", "u03B1", "u03B3", "u03B7", "u03C3", "N[max]", "Cs50", "Cr50")

        #define the lowdoseparams as factors in the same order as the labels
        lowdoseparams<-factor(lowdoseparams, levels =lowdoseparams)
        #create the labels
        xlabels<-expression(V, k, k['a'], alpha, gamma, eta, sigma, N[max], Cs[50], Cr[50])

        lowdata <- data.frame(Parameters=lowdoseparams, Effects=lowdose)
        p_low<-ggplot(data=lowdata, aes(x=Parameters, y=Effects)) +
        geom_bar(stat="identity")+
        theme(axis.text=element_text(size=14),axis.title=element_text(size=18)) +
        scale_x_discrete(labels= xlabels)
        p_low


        Looks like the xlabels vector of type "expression" cannot be added to the dataframe but must remain as an independent vector.



        enter image description here






        share|improve this answer




























          3












          3








          3







          Using this question as referenece: Subscript letters in ggplot axis label



          Here is a solution using the expression function to create the x axis labels:



          library(ggplot2)

          lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)
          lowdoseparams <-c("V", "k", "k[a]", "u03B1", "u03B3", "u03B7", "u03C3", "N[max]", "Cs50", "Cr50")

          #define the lowdoseparams as factors in the same order as the labels
          lowdoseparams<-factor(lowdoseparams, levels =lowdoseparams)
          #create the labels
          xlabels<-expression(V, k, k['a'], alpha, gamma, eta, sigma, N[max], Cs[50], Cr[50])

          lowdata <- data.frame(Parameters=lowdoseparams, Effects=lowdose)
          p_low<-ggplot(data=lowdata, aes(x=Parameters, y=Effects)) +
          geom_bar(stat="identity")+
          theme(axis.text=element_text(size=14),axis.title=element_text(size=18)) +
          scale_x_discrete(labels= xlabels)
          p_low


          Looks like the xlabels vector of type "expression" cannot be added to the dataframe but must remain as an independent vector.



          enter image description here






          share|improve this answer















          Using this question as referenece: Subscript letters in ggplot axis label



          Here is a solution using the expression function to create the x axis labels:



          library(ggplot2)

          lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)
          lowdoseparams <-c("V", "k", "k[a]", "u03B1", "u03B3", "u03B7", "u03C3", "N[max]", "Cs50", "Cr50")

          #define the lowdoseparams as factors in the same order as the labels
          lowdoseparams<-factor(lowdoseparams, levels =lowdoseparams)
          #create the labels
          xlabels<-expression(V, k, k['a'], alpha, gamma, eta, sigma, N[max], Cs[50], Cr[50])

          lowdata <- data.frame(Parameters=lowdoseparams, Effects=lowdose)
          p_low<-ggplot(data=lowdata, aes(x=Parameters, y=Effects)) +
          geom_bar(stat="identity")+
          theme(axis.text=element_text(size=14),axis.title=element_text(size=18)) +
          scale_x_discrete(labels= xlabels)
          p_low


          Looks like the xlabels vector of type "expression" cannot be added to the dataframe but must remain as an independent vector.



          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 '18 at 18:41

























          answered Nov 19 '18 at 18:02









          Dave2eDave2e

          6,941112328




          6,941112328

























              1














              I guess you can use this unicode subscript lookup table. For example U2090 is for a





              library(ggplot2)

              lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)
              lowdoseparams <- c("V", "k", "kU2090", "u03B1", "u03B3", "u03B7", "u03C3", "Nmax", "Cs50", "Cr50")
              lowdata <- data.frame(Parameters = lowdoseparams, Effects = lowdose)

              p_low <- ggplot(data = lowdata, aes(x = Parameters, y = Effects)) +
              geom_col() +
              theme(
              axis.text = element_text(size = 14),
              axis.title = element_text(size = 18)
              )
              p_low




              Created on 2018-11-19 by the reprex package (v0.2.1.9000)






              share|improve this answer




























                1














                I guess you can use this unicode subscript lookup table. For example U2090 is for a





                library(ggplot2)

                lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)
                lowdoseparams <- c("V", "k", "kU2090", "u03B1", "u03B3", "u03B7", "u03C3", "Nmax", "Cs50", "Cr50")
                lowdata <- data.frame(Parameters = lowdoseparams, Effects = lowdose)

                p_low <- ggplot(data = lowdata, aes(x = Parameters, y = Effects)) +
                geom_col() +
                theme(
                axis.text = element_text(size = 14),
                axis.title = element_text(size = 18)
                )
                p_low




                Created on 2018-11-19 by the reprex package (v0.2.1.9000)






                share|improve this answer


























                  1












                  1








                  1







                  I guess you can use this unicode subscript lookup table. For example U2090 is for a





                  library(ggplot2)

                  lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)
                  lowdoseparams <- c("V", "k", "kU2090", "u03B1", "u03B3", "u03B7", "u03C3", "Nmax", "Cs50", "Cr50")
                  lowdata <- data.frame(Parameters = lowdoseparams, Effects = lowdose)

                  p_low <- ggplot(data = lowdata, aes(x = Parameters, y = Effects)) +
                  geom_col() +
                  theme(
                  axis.text = element_text(size = 14),
                  axis.title = element_text(size = 18)
                  )
                  p_low




                  Created on 2018-11-19 by the reprex package (v0.2.1.9000)






                  share|improve this answer













                  I guess you can use this unicode subscript lookup table. For example U2090 is for a





                  library(ggplot2)

                  lowdose <- c(3.412681e-03, 1.700527e-03, 1.207575e-04, 8.716199e-03, 8.186021e-05, 1.286261e-03, 5.872725e-04, 7.124678e-02, 2.107681e-01, 3.543541e-01)
                  lowdoseparams <- c("V", "k", "kU2090", "u03B1", "u03B3", "u03B7", "u03C3", "Nmax", "Cs50", "Cr50")
                  lowdata <- data.frame(Parameters = lowdoseparams, Effects = lowdose)

                  p_low <- ggplot(data = lowdata, aes(x = Parameters, y = Effects)) +
                  geom_col() +
                  theme(
                  axis.text = element_text(size = 14),
                  axis.title = element_text(size = 18)
                  )
                  p_low




                  Created on 2018-11-19 by the reprex package (v0.2.1.9000)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 '18 at 18:17









                  TungTung

                  8,79622440




                  8,79622440






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379014%2fbarplot-label-subscripts-without-using-expression%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Guess what letter conforming each word

                      Port of Spain

                      Run scheduled task as local user group (not BUILTIN)