In chemistry, affinity of reaction A is the negative partial derivative of Gibbs free energy with respect to extent of reaction ξ at constant pressure and temperature. [1] This is shown below:

The affinity of reaction is positive for spontaneous reactions and negative for non-spontaneous reactions: [2]
● A > 0 the reaction proceeds to the right
● A < 0 the reaction proceeds to the left
The above derivation stems from the 1922 work of Belgian mathematical physicist Théophile de Donder and is built on the "chemical potential" theories of American engineering thermodynamicist Willard Gibbs and the "free energy" logic of German physician and physicist Hermann von Helmholtz and others, formulating a relation between chemical affinity A and Gibbs free energy G. De Donder showed that if we consider a mixture of chemical species, e.g. a system of reactive humans, with the possibility of chemical reaction, the measure of affinity felt between the reacting species is equal to the negative of the Gibbs free energy of formation ∆G for the reaction: [3]
A = - ΔG
References
1. Affinity of reaction – IUPAC Gold Book.
2. Kondepudi, Dilip and Prigogine, Ilya. (1998). Modern Thermodynamics – from Heat Engines to Dissipative Structures, (section: “Chemical Potential and Affinity: the Driving Force of Chemical Reactions”, pgs. 103-13). New York: John Wiley & Sons.
3. (a) De Donder, T. (1922). “ ”. Bull. Ac. Roy. Belg. (Cl. Sc.) (5) 7: 197-205.
(b) De Donder, T. (1927). “L’ Affinite”, Paris: Gauthier-Villars.
(c) De Donder, T. (1936). Thermodynamic Theory of Affinity: A Book of Principles. Oxford: Oxford University Press.
(d) De Donder, T. and Van Rysselberghe P. (1936). Affinity. Menlo Park, CA: Stanford University Press.
(e) Affinity (definition); source: Perrot, P. (1998). A to Z of Thermodynamics (dictionary). Oxford: Oxford University Press.